如何设置 CameraX (Android) 在 5 秒后停止录制?
How to set up CameraX (Android) to stop recording after 5 seconds?
这是我目前使用的代码。如果我想在 5 秒后自动停止录制视频,我不知道在哪里调用 mCameraView.stopRecording() 。目前的做法是通过按钮点击的setOnClickListener
build.gradle
def camerax_version = "1.0.0-beta08"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-view:1.0.0-alpha15"
implementation "androidx.camera:camera-extensions:1.0.0-alpha15"
MainActivity.java
CameraView mCameraView;
mCameraView.setCaptureMode(CameraView.CaptureMode.VIDEO);
mCameraView.startRecording(file, executor, new VideoCapture.OnVideoSavedCallback() {
@Override
public void onVideoSaved(@NonNull OutputFileResults outputFileResults) {
// save video file
}
@Override
public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
mCameraView.stopRecording();
}
运行 延迟后的代码
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
mCameraView.stopRecording();
}
}, 5000);
这是我目前使用的代码。如果我想在 5 秒后自动停止录制视频,我不知道在哪里调用 mCameraView.stopRecording() 。目前的做法是通过按钮点击的setOnClickListener
build.gradle
def camerax_version = "1.0.0-beta08"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-view:1.0.0-alpha15"
implementation "androidx.camera:camera-extensions:1.0.0-alpha15"
MainActivity.java
CameraView mCameraView;
mCameraView.setCaptureMode(CameraView.CaptureMode.VIDEO);
mCameraView.startRecording(file, executor, new VideoCapture.OnVideoSavedCallback() {
@Override
public void onVideoSaved(@NonNull OutputFileResults outputFileResults) {
// save video file
}
@Override
public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
mCameraView.stopRecording();
}
运行 延迟后的代码
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
mCameraView.stopRecording();
}
}, 5000);