Skip to content

Commit

Permalink
fix(record): android crash fix (react-native-camera#2697)
Browse files Browse the repository at this point in the history
Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
  • Loading branch information
cristianoccazinsp and cristianocca committed Feb 5, 2020
1 parent 9b4af8e commit 7c2572d
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions android/src/main/java/com/google/android/cameraview/Camera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -1414,26 +1414,33 @@ private void setUpMediaRecorder(String path, int maxDuration, int maxFileSize, b

private void stopMediaRecorder() {

if (mMediaRecorder != null) {
try {
mMediaRecorder.stop();
} catch (RuntimeException ex) {
Log.e("CAMERA_1::", "stopMediaRecorder failed", ex);
}
mMediaRecorder.reset();
mMediaRecorder.release();
mMediaRecorder = null;
}
synchronized(this){
if (mMediaRecorder != null) {
try {
mMediaRecorder.stop();
} catch (RuntimeException ex) {
Log.e("CAMERA_1::", "stopMediaRecorder stop failed", ex);
}

int deviceOrientation = displayOrientationToOrientationEnum(mDeviceOrientation);
if (mVideoPath == null || !new File(mVideoPath).exists()) {
mCallback.onVideoRecorded(null, mOrientation != Constants.ORIENTATION_AUTO ? mOrientation : deviceOrientation, deviceOrientation);
return;
}
try{
mMediaRecorder.reset();
mMediaRecorder.release();
} catch (RuntimeException ex) {
Log.e("CAMERA_1::", "stopMediaRecorder reset failed", ex);
}

mCallback.onVideoRecorded(mVideoPath, mOrientation != Constants.ORIENTATION_AUTO ? mOrientation : deviceOrientation, deviceOrientation);
mVideoPath = null;
mMediaRecorder = null;
}

int deviceOrientation = displayOrientationToOrientationEnum(mDeviceOrientation);
if (mVideoPath == null || !new File(mVideoPath).exists()) {
mCallback.onVideoRecorded(null, mOrientation != Constants.ORIENTATION_AUTO ? mOrientation : deviceOrientation, deviceOrientation);
return;
}

mCallback.onVideoRecorded(mVideoPath, mOrientation != Constants.ORIENTATION_AUTO ? mOrientation : deviceOrientation, deviceOrientation);
mVideoPath = null;
}
}

private void setCamcorderProfile(CamcorderProfile profile, boolean recordAudio) {
Expand Down

0 comments on commit 7c2572d

Please sign in to comment.