-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Video capture #69
Video capture #69
Conversation
@@ -24,8 +28,18 @@ | |||
import androidx.camera.core.ImageCaptureException; | |||
import androidx.camera.core.Preview; | |||
import androidx.camera.lifecycle.ProcessCameraProvider; | |||
import androidx.camera.video.FileOutputOptions; | |||
import androidx.camera.video.MediaStoreOutputOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import androidx.camera.video.MediaStoreOutputOptions; |
src/android/SimpleCameraPreview.java
Outdated
return true; | ||
} | ||
|
||
fragment.captureVideo( useFlash, new VideoCallback() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fragment.captureVideo( useFlash, new VideoCallback() { | |
fragment.captureVideo(useFlash, new VideoCallback() { |
if (torchActivated) { | ||
useFlash = true; | ||
} else { | ||
camera.getCameraControl().enableTorch(useFlash); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (torchActivated) { | |
useFlash = true; | |
} else { | |
camera.getCameraControl().enableTorch(useFlash); | |
} | |
if (torchActivated) { | |
useFlash = true; | |
} else { | |
camera.getCameraControl().enableTorch(useFlash); | |
} |
Some lines not indented properly xD
} catch (IllegalArgumentException e) { | ||
// Error with result in capturing image with default resolution | ||
e.printStackTrace(); | ||
this.getActivity().runOnUiThread(() -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.getActivity().runOnUiThread(() -> { | |
this.getActivity().runOnUiThread(() -> { |
Why do we need to run this on UI thread?
.withAudioEnabled() | ||
.start(ContextCompat.getMainExecutor(this.getContext()), videoRecordEvent -> { | ||
if (videoRecordEvent instanceof VideoRecordEvent.Start) { | ||
videoCallback.onStart(null,true, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
videoCallback.onStart(null,true, null); | |
videoCallback.onStart(null, true, null); |
@@ -102,9 +124,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c | |||
return containerView; | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…mple-camera-preview into video-rrecording
src/android/SimpleCameraPreview.java
Outdated
} | ||
} | ||
|
||
public void onStop(Exception err, Boolean started, String nativePath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void onStop(Exception err, Boolean started, String nativePath) { | |
public void onStop(Exception err, Boolean recording, String nativePath) { |
The parameter is named recording
in the interface. Should we keep the name as recording?
// Handle video saved | ||
videoCallback.onStop(null, false, Uri.fromFile(videoFile).toString()); | ||
Uri savedUri = finalizeEvent.getOutputResults().getOutputUri(); | ||
Log.d(TAG, "Video saved to: " + savedUri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log.d(TAG, "Video saved to: " + savedUri); | |
Log.i(TAG, "Video saved to: " + savedUri); |
void onStart(Exception err,Boolean recording, String nativePath); | ||
void onStop(Exception err, Boolean recording, String nativePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not using the parameter Exception err
when defining the callbacks. Should we remove it?
if (torchActivated) { | ||
useFlash = true; | ||
} else { | ||
camera.getCameraControl().enableTorch(useFlash); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (torchActivated) { | |
useFlash = true; | |
} else { | |
camera.getCameraControl().enableTorch(useFlash); | |
} | |
if (!torchActivated) { | |
camera.getCameraControl().enableTorch(useFlash); | |
} |
This will work right?
In the if
block, useFlash
is being reassigned but we the argument is used only in the else
block.
@@ -258,6 +277,54 @@ public void hasFlash(HasFlashCallback hasFlashCallback) { | |||
hasFlashCallback.onResult(camera.getCameraInfo().hasFlashUnit()); | |||
} | |||
|
|||
public void captureVideo(VideoCallback videoCallback) { | |||
if (recording != null) { | |||
recording.stop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recording.stop(); | |
recording.stop(); | |
recording = null; |
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(MediaStore.Video.Media.DISPLAY_NAME, filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContentValues contentValues = new ContentValues(); | |
contentValues.put(MediaStore.Video.Media.DISPLAY_NAME, filename); | |
ContentValues contentValues = new ContentValues(); | |
contentValues.put(MediaStore.Video.Media.DISPLAY_NAME, filename); |
not used
ActivityCompat.requestPermissions(this.getActivity(), new String[]{Manifest.permission.RECORD_AUDIO}, 200); | ||
} | ||
File videoFile = new File( | ||
getContext().getApplicationContext().getFilesDir(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getContext().getApplicationContext().getFilesDir(), | |
getContext().getFilesDir(), |
Log.e(TAG, "Video recording error: " + errorCode, errorCause); | ||
} else { | ||
// Handle video saved | ||
videoCallback.onStop(false, Uri.fromFile(videoFile).toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to move this line after the log(line 317)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For audio permission deny part, we can treat it same as we do for image picker.
Before starting video capture :
1)we first request permission
2)then we check if it has permission
3) if it has, we start recording withAudioEnabled else start it without
videoCallback.onStop(false, Uri.fromFile(videoFile).toString()); | ||
Uri savedUri = finalizeEvent.getOutputResults().getOutputUri(); | ||
Log.i(TAG, "Video saved to: " + savedUri); | ||
recording = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this on line 325? since we are not setting the recording to null if finalizeEvent.hasError()
…mple-camera-preview into video-rrecording
…mple-camera-preview into video-rrecording
Allow plugin to capture video.