Is the orientation of the video saved in the saved file and / or returned as a result of the intent?
AOSP VideoCamera activity sets the rotation value of the camera device to the MediaRecorder.setOrientationHint() method. Here is a snippet of code in the VideoCamera.initializeRecorder() code associated with this:
// See android.hardware.Camera.Parameters.setRotation for // documentation. // Note that mOrientation here is the device orientation, which is // the opposite of what getWindowManager().getDefaultDisplay().getRotation() // would return, which is the orientation the graphics need to rotate // in order to render correctly. int rotation = 0; if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) { CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId]; if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - mOrientation + 360) % 360; } else { // back-facing camera rotation = (info.orientation + mOrientation) % 360; } } mMediaRecorder.setOrientationHint(rotation);
Here's the documentation for setOrientationHint() explaining how to save information:
Sets the orientation hint for playing the output video. This method should be called before preparation (). This method will not cause the original video frame to rotate during video recording, but to add a composite matrix containing the rotation angle in the output video if the output format is OutputFormat.THREE_GPP or OutputFormat.MPEG_4 so that the video player can choose the correct orientation for playback. Please note that some video players may ignore the composting matrix in the video during playback.
Since you are using the VideoView framework VideoView to play videos, it should already correctly process the information in the composition matrix, and you only need to compare the width and height of the video to decide whether to set the landscape or portrait orientation for your playback activity. One easy way to do this is to simply call ThumbnailUtils.createVideoThumbnail() (which internally uses MediaMetaDataRetriever ) and check the resolution of the returned bitmap.
source share