Android camera preview freezes when switching cameras?

元气小坏坏 提交于 2019-12-06 07:17:54

You are pretty close, you dont need to destroy the surface view everytime you switch the camera, you only need to destroy the camera session and then make sure you re hook up the camera back to the surfaceview so it can be displayed. I was having some trouble with your front facing rear facing logic on a Razr Max so I just switched it to 1 and 0.

    private void SwitchCamera() {

    if (mCamera != null) {
        mCamera.stopPreview();
        mCamera.release();
         mCamera = null;
    }

    //swap the id of the camera to be used
    if (currentCameraId == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        currentCameraId = 0;
    } else  {
        currentCameraId = 1;
    }

    mCamera = GetCameraInstance(currentCameraId);

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