Android Camera - app passed NULL surface

会有一股神秘感。 提交于 2019-12-05 00:33:10

05-22 11:27:24.977 16750-16750/com.egomez.facedetection I/CameraActivity﹕ Switching Camera 05-22 11:27:25.219 16750-16750/com.egomez.facedetection D/Camera﹕ app passed NULL surface

To get rid of that error I had to get holder of SurfaceView (on the scenario I was attempting to fix was Switching from front camera to back camera and viceversa).

    public void switchCamera(){
    Log.i(TAG, "Switching Camera");
    if (mCamera != null) {
        mCamera.stopPreview();
        mCamera.release();
        //mCamera = null;
    }

    //swap the id of the camera to be used
    if (camId == Camera.CameraInfo.CAMERA_FACING_BACK) {
        camId = Camera.CameraInfo.CAMERA_FACING_FRONT;
    }else {
        camId = Camera.CameraInfo.CAMERA_FACING_BACK;
    }
    try {
        mCamera = Camera.open(camId);
        //mCamera.setDisplayOrientation(90);
        //You must get the holder of SurfaceView!!!
        mCamera.setPreviewDisplay(mView.getHolder());
        //Then resume preview...
        mCamera.startPreview();
    }
    catch (Exception e) { e.printStackTrace(); }
}

Hope it helps for anyone running into similar issue.

Thats not true. Just set up a small delay with a Handler and it works fine on Nexus too.

Just had the problem myself with black Pictures on those devices but with 1sec of delay everything works fine

All camera things and stuff must be created from Activity for example OnCreate or something, signal for take photo can be pushed from different context.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!