1

正如标题所说,我有这个代码来准备我的录音机:

private boolean prepareMediaRecorder(){
    myCamera = getCameraInstance();

    Camera.Parameters p = myCamera.getParameters();

    p.set("orientation", "landscape");
    p.set("rotation", 90);
    myCamera.setParameters(p);

    myCamera.setDisplayOrientation(90);

    myCamera.unlock();
    mediaRecorder = new MediaRecorder();
    mediaRecorder.setCamera(myCamera);

    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

    File tempFile = new File(Environment.getExternalStorageDirectory(), "/rec/temp/video_" + String.valueOf(videoCount) + ".mp4");
    mediaRecorder.setOutputFile(tempFile.getPath());
    mediaRecorder.setMaxDuration(12500); // Set max duration 11 sec.
    mediaRecorder.setMaxFileSize(7000000); // Set max file size 7M

    mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());


    try {
        mediaRecorder.prepare();
    } catch (IllegalStateException e) {
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        releaseMediaRecorder();
        return false;
    }
    return true;

}

我的表面观点是:

@Override
    public void surfaceChanged(SurfaceHolder holder, int format, int weight,
            int height) {
        // If your preview can change or rotate, take care of those events here.
        // Make sure to stop the preview before resizing or reformatting it.

        if (mHolder.getSurface() == null){
          // preview surface does not exist
          return;
        }

        // stop preview before making changes
        try {
            mCamera.stopPreview();
        } catch (Exception e){
          // ignore: tried to stop a non-existent preview
        }

        // make any resize, rotate or reformatting changes here

        // start preview with new settings
        try {

            myCamera.setDisplayOrientation(90);

            mCamera.startPreview();

        } catch (Exception e){
        }
    }

那是唯一使用相机的两个地方(旋转)......并且在录制时一切都很好,但当我播放该视频时,它是风景。谁能告诉我为什么以及如何解决这个问题?

4

1 回答 1

2

使用 setOrientationHint(int degree) http://developer.android.com/reference/android/media/MediaRecorder.html#setOrientationHint(int)

mediaRecorder.setOrientationHint(90); (90 用于后置摄像头,270 用于前置摄像头)在 mediaRecorder.prepare() 之前调用它;

于 2013-10-18T19:18:15.233 回答