Merge pull request #993 from RZulfikri/master

Video Orientation By Device Orientation
This commit is contained in:
João Guilherme Fidelis 2018-03-10 12:50:11 -03:00 committed by GitHub
commit 0e29f466d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 5 deletions

View File

@ -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;
}