Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 相机有时会倒拍_Android_Camera_Orientation_Landscape_Mediarecorder - Fatal编程技术网

Android 相机有时会倒拍

Android 相机有时会倒拍,android,camera,orientation,landscape,mediarecorder,Android,Camera,Orientation,Landscape,Mediarecorder,当我在景观中时,如果它处于0度,它会捕捉到一个很好的视频,但是如果我将手机翻转180度,它会倒转录制,我该如何改变这一点? 当我开始录制时,我执行以下代码: myMediaRecorder.setPreviewDisplay(mySurfaceHolder.getSurface()); if (rotationInDegreeValue == 90) { LogService.log(TAG, "set orientation hint : " + 0)

当我在景观中时,如果它处于0度,它会捕捉到一个很好的视频,但是如果我将手机翻转180度,它会倒转录制,我该如何改变这一点? 当我开始录制时,我执行以下代码:

myMediaRecorder.setPreviewDisplay(mySurfaceHolder.getSurface());

        if (rotationInDegreeValue == 90) {
            LogService.log(TAG, "set orientation hint : " + 0);
            myMediaRecorder.setOrientationHint(0);
        } else if (rotationInDegreeValue == 270) {
            LogService.log(TAG, "set orientation hint : " + 180);// 180
            myMediaRecorder.setOrientationHint(180);
        }

        myMediaRecorder.prepare();
        myMediaRecorder.start();
然后,我有一个定向听众:

orientationListener = new OrientationEventListener(getActivity(), SensorManager.SENSOR_DELAY_UI) {

        @Override
        public void onOrientationChanged(int orientation) {
            LogService.log(TAG, "onOrientationChanged");

            if ((myCamera == null)) {
                return;
            }
            Log.d(TAG, "orientation changed : " + orientation);
            if (((orientation < 45) || (orientation > 315) || ((orientation < 225) && (orientation > 135))) && !isRecording) {
                if (!isAlertShown && !isUserListDisplayed) {
                    // AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                    // alertDialogBuilder.setTitle("Orientation").setMessage("Return to landscape").setCancelable(false);
                    // orientationAlert = alertDialogBuilder.create();
                    // orientationAlert.show();
                    isAlertShown = true;
                }

            } else {
                if (isAlertShown) {
                    // orientationAlert.hide();
                    // orientationAlert.dismiss();
                    isAlertShown = false;
                }
            }
            rotateCamera();
        }
    };
当我将手机旋转180度时,我必须做什么,才能阻止摄像头倒转录制。我试着对听众进行评论,但还是没有成功。
另外,我不知道这是否重要,但这发生在一个片段中。片段的活动未设置OnConfiguration Changed。

setOrientationHint函数起作用,但我必须附加更多视频,当发生这种情况时,视频的合成矩阵丢失了。
我在清单中进行了更改,从Sensor横向到横向,这就是我解决这个问题的方法。

setOrientionHint函数起作用,但我必须附加更多视频,当发生这种情况时,视频的合成矩阵丢失了。
我在清单中从Sensor横向切换到横向,这就是我解决这个问题的方法。

正如代码所示,如果手机旋转180度,当我开始录制时,视频是正常的,而我录制时,如果我将手机旋转到正常(0度),它仍然是正常的。问题是,如果我想观看视频,录制的视频开始时是颠倒的(而不是正常的),只有当我将手机旋转到0度时才转为正常,因为代码是已知的,如果手机旋转180度,当我开始录制时,视频是正常的,而我正在录制,如果我将手机转为正常(0度),这仍然是正常的。问题是,如果我想观看视频,录制的视频开始时是颠倒的(而不是正常的),只有当我将手机旋转到0度时才转为正常
private void rotateCamera() {

    LogService.log(TAG, "rotateCamera()");

    int cameraId = CameraInfo.CAMERA_FACING_BACK;

    if (isUsingBackCam) {
        cameraId = CameraInfo.CAMERA_FACING_FRONT;
    }
    android.hardware.Camera.CameraInfo myCameraInfo = new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, myCameraInfo);
    Display display;
    display = getActivity().getWindow().getWindowManager().getDefaultDisplay();

    int rotation = display.getRotation();
    int degrees = 0;

    Point size = new Point();
    display.getSize(size);
    switch (rotation) {
    case Surface.ROTATION_0:
        degrees = 0;
        rotationInDegreeValue = 0;
        SCREEN_HEIGHT = size.x;

        break;
    case Surface.ROTATION_90:
        degrees = 90;
        rotationInDegreeValue = 90;
        SCREEN_HEIGHT = size.y;
        break;
    case Surface.ROTATION_180:
        degrees = 180;
        rotationInDegreeValue = 180;
        break;
    case Surface.ROTATION_270:
        rotationInDegreeValue = 270;
        degrees = 270;
        SCREEN_HEIGHT = size.y;
        break;
    }
    int result;
    if (myCameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = (myCameraInfo.orientation + degrees) % 360;
        result = (360 - result) % 360; // compensate the mirror
    } else { // back-facing
        result = ((myCameraInfo.orientation - degrees) + 360) % 360;
    }
    if (!isRecording) {
        try {
            myCamera.setDisplayOrientation(result);
        } catch (Exception e) {
            LogService.err(TAG, e.getMessage(), e, 1);
        }
    }
}