1

我正在为我正在制作的应用程序创建一个视频捕获活动,并且我想捕获一个预览帧以及用作播放按钮。我已经在以下位置设置SurfaceViewonCreate(...)连接了相机的预览显示SurfaceHolder.Callback

private Callback mSurfaceViewCallback = new Callback() {

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        mSurfaceCreated = false;
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        try {
            mSurfaceCreated = true;
            mCamera.setPreviewDisplay(mHolder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        try {
            mSurfaceCreated = true;
            mCamera.setPreviewDisplay(mHolder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
};

这适用于静态相机应用程序。onPause()相机预览在和中打开和关闭onResume()

@Override
protected void onResume() {
    super.onResume();
    if(mCamera!=null)
        mCamera.startPreview();
}

@Override
protected void onPause() {
    if(mCamera!=null)
        mCamera.stopPreview();
    super.onPause();
}

我已经MediaRecorder这样设置了:

protected void startRecording() {
    mMediaRecorder = new MediaRecorder();
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));

    mMediaRecorder.setMaxDuration(10000);
    mMediaRecorder.setOutputFile(new File(getFilesDir(), mChallengeUUID + ".mp4").getAbsolutePath());
    mMediaRecorder.setPreviewDisplay(mHolder.getSurface());
    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mCamera.setOneShotPreviewCallback(mPreviewCallback);
    mMediaRecorder.start();
}

然而,倒数第二行不起作用。错过了我Camera.PreviewCallbackonPreviewFrame(...)方法。

正如我所说,拥有它的目的是从录制视频的开头获取一帧以显示给用户。为什么回调没有被击中?

4

1 回答 1

1

mCamera.unlock()从进程中分离相机。有必要调用:

mCamera.reconnect();

打电话之前:

mCamera.setOneShotPreviewCallback(mPreviewCallback);

(但在其他一切之后)。

于 2013-05-15T20:20:07.873 回答