|
9 | 9 | import android.os.Handler; |
10 | 10 | import android.util.Log; |
11 | 11 | import android.support.annotation.Nullable; |
| 12 | +import android.util.SparseIntArray; |
12 | 13 | import android.view.MotionEvent; |
| 14 | +import android.view.Surface; |
13 | 15 | import android.view.SurfaceHolder; |
14 | 16 | import android.view.View; |
15 | 17 |
|
@@ -49,6 +51,27 @@ public class Camera1 extends CameraImpl { |
49 | 51 | private Camera.AutoFocusCallback mAutofocusCallback; |
50 | 52 | private boolean capturingImage = false; |
51 | 53 |
|
| 54 | + |
| 55 | + private static final int SENSOR_ORIENTATION_DEFAULT_DEGREES = 90; |
| 56 | + private static final int SENSOR_ORIENTATION_INVERSE_DEGREES = 270; |
| 57 | + private static final SparseIntArray DEFAULT_ORIENTATIONS = new SparseIntArray(); |
| 58 | + private static final SparseIntArray INVERSE_ORIENTATIONS = new SparseIntArray(); |
| 59 | + |
| 60 | + static { |
| 61 | + DEFAULT_ORIENTATIONS.append(Surface.ROTATION_0, 90); |
| 62 | + DEFAULT_ORIENTATIONS.append(Surface.ROTATION_90, 0); |
| 63 | + DEFAULT_ORIENTATIONS.append(Surface.ROTATION_180, 270); |
| 64 | + DEFAULT_ORIENTATIONS.append(Surface.ROTATION_270, 180); |
| 65 | + } |
| 66 | + |
| 67 | + static { |
| 68 | + INVERSE_ORIENTATIONS.append(Surface.ROTATION_0, 270); |
| 69 | + INVERSE_ORIENTATIONS.append(Surface.ROTATION_90, 180); |
| 70 | + INVERSE_ORIENTATIONS.append(Surface.ROTATION_180, 90); |
| 71 | + INVERSE_ORIENTATIONS.append(Surface.ROTATION_270, 0); |
| 72 | + |
| 73 | + } |
| 74 | + |
52 | 75 | private int mDisplayOrientation; |
53 | 76 |
|
54 | 77 | @Facing |
@@ -492,8 +515,16 @@ private void initMediaRecorder() { |
492 | 515 |
|
493 | 516 | mVideoFile = new File(mPreview.getView().getContext().getExternalFilesDir(null), "video.mp4"); |
494 | 517 | mMediaRecorder.setOutputFile(mVideoFile.getAbsolutePath()); |
495 | | - mMediaRecorder.setOrientationHint(calculatePreviewRotation()); |
496 | 518 | mMediaRecorder.setVideoSize(mCaptureSize.getWidth(), mCaptureSize.getHeight()); |
| 519 | + |
| 520 | + switch (mCameraInfo.orientation) { |
| 521 | + case SENSOR_ORIENTATION_DEFAULT_DEGREES: |
| 522 | + mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(mCameraInfo.orientation)); |
| 523 | + break; |
| 524 | + case SENSOR_ORIENTATION_INVERSE_DEGREES: |
| 525 | + mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(mCameraInfo.orientation)); |
| 526 | + break; |
| 527 | + } |
497 | 528 | } |
498 | 529 |
|
499 | 530 | public void setProfile(CamcorderProfile profile, boolean audioEnabled) { |
|
0 commit comments