我正在使用棒棒糖在xperia z2上进行开发。
我的应用程序记录了我们使用默认大小(1920 * 1080)进行记录,或者当我使用setVideoSize(1920,1080)手动设置时,如果我提供其他分辨率,则会失败,错误代码为-19。
任何帮助将不胜感激。感谢
这是我的代码
private boolean prepareVideoRecorder()
{
mMediaRecorder = new MediaRecorder();
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
// Step 2: Set sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
mMediaRecorder.setProfile(CamcorderProfile.get( CamcorderProfile.QUALITY_HIGH));
// Step 4: Set output file
outputUri = FileUtil.createOutputFile(Type.POST_QUESTION, Type.MEDIA_VIDEO); // custom methodthat returns Uri
String path = new File(outputUri.getPath()).getAbsolutePath();
mMediaRecorder.setOutputFile(path);
// set video resolution
mMediaRecorder.setVideoSize(1600, 900); //fail
// Step 5: Set the preview output
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
// Step 6: Prepare configured MediaRecorder
try
{
mMediaRecorder.prepare();
}
catch (IllegalStateException e)
{
e.printStackTrace();
releaseMediaRecorder();
return false;
}
catch (IOException e)
{
releaseMediaRecorder();
return false;
}
return true;
}
和我的logcat
07-04 19:01:34.656: E/MediaRecorder(5996): start failed: -19
07-04 19:01:34.656: D/AndroidRuntime(5996): Shutting down VM
07-04 19:01:34.656: E/AndroidRuntime(5996): FATAL EXCEPTION: main
07-04 19:01:34.656: E/AndroidRuntime(5996): Process: com.dwaik.question, PID: 5996
07-04 19:01:34.656: E/AndroidRuntime(5996): java.lang.RuntimeException: start failed.
07-04 19:01:34.656: E/AndroidRuntime(5996): at android.media.MediaRecorder.start(Native Method)
07-04 19:01:34.656: E/AndroidRuntime(5996): at com.dwaik.question.fragments.CaptureVideoFragment.startRecording(CaptureVideoFragment.java:243)
07-04 19:01:34.656: E/AndroidRuntime(5996): at com.dwaik.question.fragments.CaptureVideoFragment.onClick(CaptureVideoFragment.java:404)
07-04 19:01:34.656: E/AndroidRuntime(5996): at android.view.View.performClick(View.java:4832)
07-04 19:01:34.656: E/AndroidRuntime(5996): at android.view.View$PerformClick.run(View.java:19839)
07-04 19:01:34.656: E/AndroidRuntime(5996): at android.os.Handler.handleCallback(Handler.java:739)
07-04 19:01:34.656: E/AndroidRuntime(5996): at android.os.Handler.dispatchMessage(Handler.java:95)
07-04 19:01:34.656: E/AndroidRuntime(5996): at android.os.Looper.loop(Looper.java:211)
07-04 19:01:34.656: E/AndroidRuntime(5996): at android.app.ActivityThread.main(ActivityThread.java:5321)
07-04 19:01:34.656: E/AndroidRuntime(5996): at java.lang.reflect.Method.invoke(Native Method)
07-04 19:01:34.656: E/AndroidRuntime(5996): at java.lang.reflect.Method.invoke(Method.java:372)
07-04 19:01:34.656: E/AndroidRuntime(5996): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
07-04 19:01:34.656: E/AndroidRuntime(5996): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
答案 0 :(得分:0)
CamcorderProfile.QUALITY_HIGHT已自动设置手机中的最高分辨率(http://developer.android.com/reference/android/media/CamcorderProfile.html)。
因此,手动设置分辨率可能会在MediaPlayer参数中产生一些不一致。
此外,您的手机可能没有您尝试设置的分辨率(1600x900)。您可以通过Camera.Parameters中的方法getSupportedVideoSizes()获取可用的分辨率。
我的建议:要么使用CamcorderProfile(我更喜欢),要么手动设置。帧速率限制也可能因手机而异。