Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera onPreviewFrame not called

Tags:

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.

like image 931
esse Avatar asked Aug 12 '11 15:08

esse


1 Answers

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()); } } 
like image 59
Neonigma Avatar answered Sep 19 '22 06:09

Neonigma