Save video when back button pressed while recording

This commit is contained in:
Sagar 2025-01-23 20:45:18 +05:30
parent 49d6eb1a44
commit c3d832bd93
4 changed files with 19 additions and 2 deletions

View file

@ -236,6 +236,10 @@ public class Camera1Fragment extends LoggingFragment implements CameraFragment,
});
}
@Override public void stopVideoRecording() {
throw new UnsupportedOperationException("Camera1 does not support this operation");
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Log.d(TAG, "onSurfaceTextureAvailable");

View file

@ -55,6 +55,7 @@ public interface CameraFragment {
void presentHud(int selectedMediaCount);
void fadeOutControls(@NonNull Runnable onEndAction);
void fadeInControls();
void stopVideoRecording();
interface Controller {
void onCameraError();

View file

@ -98,6 +98,7 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
private View selfieFlash;
private MemoryFileDescriptor videoFileDescriptor;
private LifecycleCameraController cameraController;
private CameraXVideoCaptureHelper cameraXVideoCaptureHelper;
private Disposable mostRecentItemDisposable = Disposable.disposed();
private CameraXModePolicy cameraXModePolicy;
private CameraScreenBrightnessController cameraScreenBrightnessController;
@ -229,6 +230,12 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
@Override public void stopVideoRecording() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
cameraXVideoCaptureHelper.onVideoCaptureComplete();
}
}
@Override
public void fadeOutControls(@NonNull Runnable onEndAction) {
controlsContainer.setEnabled(false);
@ -439,7 +446,7 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
Log.d(TAG, "Max duration: " + maxDuration + " sec");
captureButton.setVideoCaptureListener(new CameraXVideoCaptureHelper(
cameraXVideoCaptureHelper = new CameraXVideoCaptureHelper(
this,
captureButton,
lifecycleCameraController,
@ -466,7 +473,8 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
controller.onVideoCaptureError();
}
}
));
);
captureButton.setVideoCaptureListener(cameraXVideoCaptureHelper);
displayVideoRecordingTooltipIfNecessary(captureButton);
} catch (IOException e) {
Log.w(TAG, "Video capture is not supported on this device.", e);

View file

@ -124,6 +124,10 @@ class MediaCaptureFragment : Fragment(R.layout.fragment_container), CameraFragme
viewLifecycleOwner,
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if(sharedViewModel.isVideoRecording.value==true) {
captureChildFragment.stopVideoRecording()
return
}
requireActivity().finish()
}
}