From 875c00a5ca9b39c29ddf6e03343bf6c6ea3fc5d0 Mon Sep 17 00:00:00 2001 From: Rahmat Date: Mon, 20 Nov 2017 10:16:06 +0700 Subject: [PATCH 1/2] change video orientation by device orientation --- .../RCTCamera/RCTCameraModule.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java b/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java index 9247b6b..8d4f1c8 100644 --- a/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java +++ b/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java @@ -259,7 +259,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule * @param options Options. * @return Throwable; null if no errors. */ - private Throwable prepareMediaRecorder(ReadableMap options) { + private Throwable prepareMediaRecorder(ReadableMap options, int deviceOrientation) { // Prepare CamcorderProfile instance, setting essential options. CamcorderProfile cm = RCTCamera.getInstance().setCaptureVideoQuality(options.getInt("type"), options.getString("quality")); if (cm == null) { @@ -286,7 +286,16 @@ public class RCTCameraModule extends ReactContextBaseJavaModule mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); // Adjust for orientation. - mMediaRecorder.setOrientationHint(RCTCamera.getInstance().getAdjustedDeviceOrientation()); + // mMediaRecorder.setOrientationHint(RCTCamera.getInstance().getAdjustedDeviceOrientation()); + switch (deviceOrientation) { + case 0: mMediaRecorder.setOrientationHint(90); + break; + case 1: mMediaRecorder.setOrientationHint(0); + break; + case 2: mMediaRecorder.setOrientationHint(270); + break; + case 3: mMediaRecorder.setOrientationHint(180); + } // Set video output format and encoding using CamcorderProfile. cm.fileFormat = MediaRecorder.OutputFormat.MPEG_4; @@ -336,7 +345,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule return null; } - private void record(final ReadableMap options, final Promise promise) { + private void record(final ReadableMap options, final Promise promise, final int deviceOrientation) { if (mRecordingPromise != null) { return; } @@ -347,7 +356,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule return; } - Throwable prepareError = prepareMediaRecorder(options); + Throwable prepareError = prepareMediaRecorder(options, deviceOrientation); if (prepareError != null) { promise.reject(prepareError); return; @@ -511,7 +520,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule } if (options.getInt("mode") == RCT_CAMERA_CAPTURE_MODE_VIDEO) { - record(options, promise); + record(options, promise, deviceOrientation); return; } From 5572ba70682773dc1251f1842ccf8803f2270e93 Mon Sep 17 00:00:00 2001 From: Rahmat Date: Mon, 20 Nov 2017 12:26:46 +0700 Subject: [PATCH 2/2] missing break on switch --- .../src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java b/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java index 8d4f1c8..db18bb3 100644 --- a/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java +++ b/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java @@ -295,6 +295,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule case 2: mMediaRecorder.setOrientationHint(270); break; case 3: mMediaRecorder.setOrientationHint(180); + break; } // Set video output format and encoding using CamcorderProfile.