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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With