mirror of
https://github.com/status-im/react-native-camera.git
synced 2026-08-31 13:41:08 +00:00
Merge pull request #993 from RZulfikri/master
Video Orientation By Device Orientation
This commit is contained in:
@@ -258,7 +258,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) {
|
||||
@@ -285,7 +285,17 @@ 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);
|
||||
break;
|
||||
}
|
||||
|
||||
// Set video output format and encoding using CamcorderProfile.
|
||||
cm.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
|
||||
@@ -335,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;
|
||||
}
|
||||
@@ -346,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;
|
||||
@@ -515,7 +525,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
|
||||
}
|
||||
|
||||
if (options.getInt("mode") == RCT_CAMERA_CAPTURE_MODE_VIDEO) {
|
||||
record(options, promise);
|
||||
record(options, promise, deviceOrientation);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user