Android Front Camera recording video but plays upside down…!

淺唱寂寞╮ 提交于 2019-12-07 17:55:50

You might want to look at how the AOSP VideoCamera activity is implementing this:

    if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
        rotation = (info.orientation - mOrientation + 360) % 360;
    } else {  // back-facing camera
        rotation = (info.orientation + mOrientation) % 360;
    }

There are some more details in my answer for another question here.

android_beginner

Add this where you start you video recording below setVideoSource

mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
if (cameraId == 1) {
    mediaRecorder.setProfile(CamcorderProfile
        .get(CamcorderProfile.QUALITY_LOW));
    mediaRecorder.setOrientationHint(270);
} else if (cameraId == 0) {
    mediaRecorder.setProfile(CamcorderProfile
        .get(CamcorderProfile.QUALITY_HIGH));
    mediaRecorder.setOrientationHint(orientation);
}

mediaRecorder.setOrientationHint(270); is for front camera upside down issue

Check the camera ID, if it is 1 then follow the orientation change for media player "setOrientationHit()

private static final SparseIntArray REAR_ORIENTATIONS = new SparseIntArray();
static {
    REAR_ORIENTATIONS.append(Surface.ROTATION_0, 270);
    REAR_ORIENTATIONS.append(Surface.ROTATION_90, 0);
    REAR_ORIENTATIONS.append(Surface.ROTATION_180, 90);
    REAR_ORIENTATIONS.append(Surface.ROTATION_270, 180);
}

Then in media player preview preparing methods as :

if(cameraId == FRONT_CAMERA) {
     mMediaRecorder.setOrientationHint(REAR_ORIENTATIONS.get(rotation));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!