问题描述
我创建了一个应用程序我正在做一个视频采集活动,我想捕捉preVIEW框架,以及一个播放按钮来使用。我给自己定了 SurfaceView
在的onCreate(...)
并迷上了相机的preVIEW显示在 SurfaceHolder.Callback
:
I'm creating a video capture activity for an app I'm making, and I want to capture a preview frame as well to use as a playback button. I've set the SurfaceView
up in onCreate(...)
and hooked up the camera's preview display in the 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();
}
}
};
这对于静态相机应用工作的罚款。相机preVIEW开启和关闭的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
像这样的:
and I've set the MediaRecorder
up like this:
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();
}
这是倒数第二行,但是,不工作。我的相机。previewCallback
的在previewFrame(...)
方法被错过。
That penultimate line, however, isn't working. My Camera.PreviewCallback
's onPreviewFrame(...)
method is being missed.
有它的目的是,正如我所说,以获得当正在录像,显示给用户的起始帧。为什么没有回调被打?
The purpose of having it is, as I say, to get a frame from the beginning of when the video is being recorded to display to the user. Why isn't the callback being hit?
推荐答案
mCamera.unlock()
从分离过程中的相机。因此有必要呼吁:
mCamera.unlock()
detaches the camera from the process. It's necessary to call:
mCamera.reconnect();
在调用之前:
before calling:
mCamera.setOneShotPreviewCallback(mPreviewCallback);
(但一切后)。
(but after everything else).
这篇关于setOneShot previewCallback不打在回调previewFrame()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!