Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PreviewCallback and PreviewCallback with buffer are not called

I have a question regarding the preview callbacks with Android 4.0.x. I set up a camera, create a surface to display camera image on previewCallback-event. Everything works fine.

But with Android 4.0.x neither onPreviewCallback is called nor onPreviewCallbackWithBuffer. Is there a workaround for this issue?

I want to take a screen shot and do not want to use the takePicture()-way because it freezes the live image for a short-time.

like image 623
tomcat.exe Avatar asked Dec 11 '12 12:12

tomcat.exe


1 Answers

You must to call setPreviewCallback in surfaceChanged method, not only in 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 72
Neonigma Avatar answered Sep 28 '22 00:09

Neonigma