Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

android - Camera onPreviewFrame not called

when using the Camera.PreviewCallback implementation the onPreviewFrame is called without problem after initializing camera and starting preview (Camera.startPrevew()). The problem is if I make a video recording using MediaRecorder onPreviewFrame does not get called any more.

I understand that when using MediaRecorder to record video stops the Camera.PreviewCallback, but why can't it be restarted?

I have tried resetting the camera preview callback (setPreviewCallback(callback)) and restarting startPreview, but while I have a preview there is no call to onPreviewFrame.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You must call setPreviewCallback in the surfaceChanged method, not only in the surfaceCreated.

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (mHolder.getSurface() == null){
  return;
}

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

try {
    mCamera.setPreviewCallback(this);
    mCamera.setPreviewDisplay(mHolder);
    mCamera.startPreview();

} catch (Exception e){
    Log.d(TAG, "Error starting camera preview: " + e.getMessage());
}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...