我正在为Camera设置参数,以便为Android应用中的视频录制做好准备。 此代码段似乎适用于多个设备,但在 LG G3 上崩溃:
java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:1852)
有谁知道其中一个参数是否对该设备有害?
p = myCamera.getParameters();
surfaceHolder = mSurfaceView.getHolder();
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
p.setPictureSize(cam_width, cam_height);
if (myCamera != null) {
try {
myCamera.setPreviewDisplay(surfaceHolder);
List<String> focusModes = p.getSupportedFocusModes();
if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO))
p.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
p.setPreviewSize(cam_width, cam_height);
int[] max = VideoQuality.determineMaximumSupportedFramerate(p);
p.setPreviewFpsRange(max[0], max[1]);
p.setRecordingHint(true);
if(myCamera != null)
myCamera.setParameters(p);
cam_width&amp; cam_height以这种方式计算:
camprev = p.getSupportedPreviewSizes();
int high_width_preview = myCamera.getParameters().getSupportedPreviewSizes().get(0).width;
int high_height_preview = myCamera.getParameters().getSupportedPreviewSizes().get(0).height;
for(int i =0; i< myCamera.getParameters().getSupportedPreviewSizes().size(); i++){
Size sizet = myCamera.getParameters().getSupportedPreviewSizes().get(i);
Log.d("TAGME_NEXT", "supported preview sizeS: " + sizet.width + " " + sizet.height);
if(sizet.width > high_width_preview) {
high_width_preview = sizet.width;
high_height_preview = sizet.height;
}
}
cam_width = high_width_preview;
cam_height = high_height_preview;
答案 0 :(得分:0)
解决了删除问题:
p.setPictureSize(cam_width, cam_height);