Android - Fail to connect to camera

前端 未结 9 1009
日久生厌
日久生厌 2020-12-30 20:29

I\'m using the Android APIDemo sample code.

When I run the CameraPreview example, at first it was giving me an error.

I traced that one down and the sample

9条回答
  •  滥情空心
    2020-12-30 21:11

    Be sure to properly release all the aquired camera resources:

        @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        if (mCam != null) {
            mCam.stopPreview();
            mCam.setPreviewCallback(null);
            mCam.release();
            mCam = null;
        }
    }
    
        @Override
    public void surfaceCreated(SurfaceHolder holder) {
        if (mCam == null) {
            mCam = Camera.open();
            try {
                mCam.setPreviewDisplay(holder);
    
                // TODO test how much setPreviewCallbackWithBuffer is faster
                mCam.setPreviewCallback(this);
            } catch (IOException e) {
                mCam.release();
                mCam = null;
            }
        }
    }
    

提交回复
热议问题