Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.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_Android Camera_Android Videoview_Android Orientation - Fatal编程技术网

Android 在安卓系统中,当从前置摄像头录制视频时,视频会颠倒播放

Android 在安卓系统中,当从前置摄像头录制视频时,视频会颠倒播放,android,android-camera,android-videoview,android-orientation,Android,Android Camera,Android Videoview,Android Orientation,我正在做android摄像机应用程序。它应该具有前后摄像头记录的能力。我已经用完了后置摄像头,一切都很好。但当我用前置摄像头录制时,视频播放颠倒了。我必须播放应用程序中录制的视频。我正在使用VideoView,如何设置方向或使其正确播放?。在默认媒体播放器中播放视频时,也会颠倒播放。尝试将视频发送到iPhone并进行了检查,但它仍然颠倒播放。我已将方向提示设置为MediaRecorder,但没有解决方案 我的所有代码都与我在其中进行定制的代码类似 这些问题似乎很奇怪,我很震惊 this.medi

我正在做android摄像机应用程序。它应该具有前后摄像头记录的能力。我已经用完了后置摄像头,一切都很好。但当我用前置摄像头录制时,视频播放颠倒了。我必须播放应用程序中录制的视频。我正在使用VideoView,如何设置方向或使其正确播放?。在默认媒体播放器中播放视频时,也会颠倒播放。尝试将视频发送到iPhone并进行了检查,但它仍然颠倒播放。我已将方向提示设置为MediaRecorder,但没有解决方案

我的所有代码都与我在其中进行定制的代码类似

这些问题似乎很奇怪,我很震惊

this.mediaRecorder = new MediaRecorder();
        this.mediaRecorder.setCamera(this.mCamera);
        this.mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        this.mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        if (Build.VERSION.SDK_INT <= 10) {
            CamcorderProfile camcorderProfile = CamcorderProfile
                    .get(CamcorderProfile.QUALITY_HIGH);
            camcorderProfile.videoFrameWidth = 320;
            camcorderProfile.videoFrameHeight = 480;
            // camcorderProfile.videoFrameRate = 15;
            camcorderProfile.videoCodec = MediaRecorder.VideoEncoder.H264;
            // camcorderProfile.audioCodec = MediaRecorder.AudioEncoder.DEFAULT;
            camcorderProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
            this.mediaRecorder.setProfile(camcorderProfile);
mediaRecorder.setOrientationHint(90);
        } else {
            if (tgbSwitchCamera.isChecked()) {
                mediaRecorder
                        .setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
                // mediaRecorder.setVideoSize(320, 480);
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
                mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
                CameraInfo cameraInfo = new CameraInfo();
                Camera.getCameraInfo(CameraInfo.CAMERA_FACING_FRONT, cameraInfo);
                rotation = (cameraInfo.orientation - 180 + 360) % 360;
                mediaRecorder.setOrientationHint(rotation);

            } else {
                CamcorderProfile camcorderProfile = CamcorderProfile
                        .get(CamcorderProfile.QUALITY_LOW);
                camcorderProfile.videoFrameWidth = 640;
                camcorderProfile.videoFrameHeight = 480;
                camcorderProfile.videoCodec = MediaRecorder.VideoEncoder.H264;
                // camcorderProfile.audioCodec =
                // MediaRecorder.AudioEncoder.DEFAULT;
                camcorderProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
                this.mediaRecorder.setProfile(camcorderProfile);
mediaRecorder.setOrientationHint(90);
            }
        }
        this.mediaRecorder.setOutputFile(this.initFile().getAbsolutePath());
        this.mediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

        try {
            this.mediaRecorder.prepare();

            // start the actual recording
            // throws IllegalStateException if not prepared
            Handler h = new Handler();
            h.postDelayed(new Runnable() {

                @Override
                public void run() {
                    this.mediaRecorder.start();
                    pgv.setStart(true);
                    pgv.invalidate();
                    CountDownTimer cdt = new CountDownTimer(5000, 1000) {

                        @Override
                        public void onTick(long millisUntilFinished) {
                        }

                        @Override
                        public void onFinish() {
                            if (isRecording) {
                                handler.removeMessages(STOP);
                                stopRecording();
                            }
                        }
                    };
                    cdt.start();
                }
            }, 1000);

            // enable the stop button by indicating that we are recording
        } catch (Exception e) {
            Toast.makeText(this, "cannot record", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
            this.releaseMediaRecorder();
        }

该行将专门将视频旋转180度:

rotation = (cameraInfo.orientation - 180 + 360) % 360;

除非你有我看不到的理由,否则这就是为什么你的视频是颠倒的

该行将专门将视频旋转180度:

rotation = (cameraInfo.orientation - 180 + 360) % 360;

除非你有我看不到的理由,否则这就是为什么你的视频是颠倒的

…我在其中进行了定制。让我们来看看定制?@Geobits,从某种意义上说是定制,而不是功能上的定制——它只是设计上的定制。好吧,看一看也无妨。你链接到的演示是基本的,没有什么可看的。当然,这也可能是硬件或平台特定的问题。然而,你还没有告诉我们你在试什么。您提供的相关细节越多,您得到的帮助就越多。@Geobits,我已经添加了我的全部用于录制的代码。startRecording和stopRecording来自上面的演示…我在其中进行了定制。让我们来看看定制?@Geobits,从某种意义上说是定制,而不是功能上的定制——它只是设计上的定制。好吧,看一看也无妨。你链接到的演示是基本的,没有什么可看的。当然,这也可能是硬件或平台特定的问题。然而,你还没有告诉我们你在试什么。您提供的相关细节越多,您得到的帮助就越多。@Geobits,我已经添加了我的全部用于录制的代码。startRecording和stopRecording来自上述演示