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.
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()); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With