I have an innerclass CameraView
that extends SurfaceView
.
Inside the surfaceChanged()
function I use the following code to set Camera parameters:
Camera.Parameters camParams = mCamera.getParameters();
List<Camera.Size> sizes = camParams.getSupportedPreviewSizes();
// Sort the list in ascending order
Collections.sort(sizes, new Comparator<Camera.Size>() {
public int compare(final Camera.Size a, final Camera.Size b) {
return a.width * a.height - b.width * b.height;
}
});
for (int i = 0; i < sizes.size(); i++) {
if ((sizes.get(i).width >= imageWidth && sizes.get(i).height >= imageHeight) || i == sizes.size() - 1) {
imageWidth = sizes.get(i).width;
imageHeight = sizes.get(i).height;
Log.e(LOG_TAG, "Resolution: " + imageWidth + " x " + imageHeight);
break;
}
}
camParams.setPreviewSize(imageWidth, imageHeight);
for(int[] arr : camParams.getSupportedPreviewFpsRange ()){
Log.e(LOG_TAG, "Supported range: " + arr[0] + " - " + arr[1]);
}
camParams.setPreviewFrameRate(frameRate);
mCamera.setParameters(camParams);
The for loop inside this print the following range: Supported range: 4000 - 60000
, which means that my device should support between 4 and 60 fps.
Now when I set frameRate = 45
(which is well withing the range), my app crashes with the following exception:
java.lang.RuntimeException: setParameters failed at android.hardware.Camera.native_setParameters(Native Method) at android.hardware.Camera.setParameters(Camera.java:1876)
This does not happen if frameRate = 30
. Can someone explain why is my app is crashing? Can the getSupportedPreviewFpsRange()
not be trusted?
Edit 1
I've now also tried camParams.setPreviewFpsRange(frameRate*1000, frameRate*1000);
, same crash result.