Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setParameters Failed in Nexus 5 and Nexus 7

I have implemented custom camera in my app. It is working fine in all device except Nexus 5 and Nexus 7. In both devices, It is crashing with SetParameters failed on camera. I have implemented custom camera with below code:

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        if (mCamera != null) {
            Log.e(TAG, "surfaceChanged called");
            Camera.Parameters parameters = mCamera.getParameters();
            if (mSupportedPreviewSizes != null) {
                mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, w,
                        h);
            }
            Log.e(TAG, "surfaceChanged : mPreviewSize height:"
                    + mPreviewSize.height + " width: " + mPreviewSize.width);
            parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);

            requestLayout();

            mCamera.setParameters(parameters);
            Log.e(TAG, "surfaceChanged called setParameters success");
        }
    }

I have found at many places comments that it is due to unsupported preview size but In my case, I am already taking it from supported preview sizes.

like image 950
chikka.anddev Avatar asked Dec 06 '25 03:12

chikka.anddev


1 Answers

I had the same issue with a Nexus tablet: the same code changing the preview size to another supported preview size worked on various tablets but not the nexus tablet I had.

In my case, the issue was that I had already started previewing before changing the preview size. Changing the preview size before starting the preview size solved my issue.

like image 148
Lolo Avatar answered Dec 08 '25 15:12

Lolo