From 78c5e4b19c36ad0a5ea3d43e351ce889f19fd341 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Sat, 3 Mar 2018 22:07:19 +0100 Subject: [PATCH] Fix VideoRecorder bug --- .../java/com/otaliastudios/cameraview/Camera1.java | 3 ++- .../cameraview/MediaRecorderVideoRecorder.java | 4 +--- .../com/otaliastudios/cameraview/VideoRecorder.java | 13 +++++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java index 7cf05202..6d0c9e13 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java @@ -205,7 +205,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera mFrameManager.release(); if (mCamera != null) { - LOG.i("onStop:", "Clean up.", "Ending video."); + LOG.i("onStop:", "Clean up.", "Ending video. mVideoRecorder is null?", mVideoRecorder == null); if (mVideoRecorder != null) { mVideoRecorder.stop(); mVideoRecorder = null; @@ -655,6 +655,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera @Override public void run() { mIsTakingVideo = false; + LOG.i("stopVideo", "mVideoRecorder is null?", mVideoRecorder == null); if (mVideoRecorder != null) { mVideoRecorder.stop(); mVideoRecorder = null; diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java index 9727fef9..dc3ba767 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java @@ -75,7 +75,7 @@ class MediaRecorderVideoRecorder extends VideoRecorder { } @Override - void stop() { + void close() { if (mMediaRecorder != null) { try { mMediaRecorder.stop(); @@ -85,8 +85,6 @@ class MediaRecorderVideoRecorder extends VideoRecorder { } mMediaRecorder.release(); } - - super.stop(); mProfile = null; mMediaRecorder = null; } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/VideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/VideoRecorder.java index 773191e2..78f9702f 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/VideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/VideoRecorder.java @@ -21,12 +21,17 @@ abstract class VideoRecorder { abstract void start(); - void stop() { - mListener.onVideoResult(mResult); - mListener = null; - mResult = null; + final void stop() { + if (mListener != null) { + close(); + mListener.onVideoResult(mResult); + mListener = null; + mResult = null; + } } + abstract void close(); + interface VideoResultListener { void onVideoResult(@Nullable VideoResult result); }