3

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.

Michael
  • 57,169
  • 9
  • 80
  • 125
chikka.anddev
  • 9,569
  • 7
  • 38
  • 46

1 Answers1

1

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.

Lolo
  • 3,935
  • 5
  • 40
  • 50