而且也发现,在使用MediaRecorder进行视频录制,调用start()方法时报错,发生
spydroid-android测试在android4.0系统上同样的错误,具体错误如下:
- 01-06 14:04:07.790: V/MediaRecorder(13280): prepare
- 01-06 14:04:07.790: V/IMediaRecorder(13280): prepare
- 01-06 14:04:07.800: V/MediaRecorder(13280): start
- 01-06 14:04:07.800: V/IMediaRecorder(13280): start
- 01-06 14:04:08.190: E/MediaRecorder(13280): start failed: -19
- 01-06 14:04:08.190: W/System.err(13280): java.lang.RuntimeException: start failed.
- 01-06 14:04:08.200: W/System.err(13280): at android.media.MediaRecorder.start(Native Method)
- 01-06 14:04:08.200: W/System.err(13280): at com.yousee.videocapturedemo.VideoCapturePlus$2.onClick(VideoCapturePlus.java:145)
- 01-06 14:04:08.200: W/System.err(13280): at android.view.View.performClick(View.java:3515)
- 01-06 14:04:08.200: W/System.err(13280): at android.view.View$PerformClick.run(View.java:14144)
- 01-06 14:04:08.200: W/System.err(13280): at android.os.Handler.handleCallback(Handler.java:605)
- 01-06 14:04:08.200: W/System.err(13280): at android.os.Handler.dispatchMessage(Handler.java:92)
- 01-06 14:04:08.200: W/System.err(13280): at android.os.Looper.loop(Looper.java:148)
- 01-06 14:04:08.200: W/System.err(13280): at android.app.ActivityThread.main(ActivityThread.java:4503)
- 01-06 14:04:08.200: W/System.err(13280): at java.lang.reflect.Method.invokeNative(Native Method)
- 01-06 14:04:08.200: W/System.err(13280): at java.lang.reflect.Method.invoke(Method.java:511)
- 01-06 14:04:08.200: W/System.err(13280): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:830)
- 01-06 14:04:08.200: W/System.err(13280): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
- 01-06 14:04:08.200: W/System.err(13280): at dalvik.system.NativeStart.main(Native Method)
MediaRecorder 初始化和设置代码如下:
- .....
- mMediaRecorder=new MediaRecorder();
-
- mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
-
- mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
-
- mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
-
- mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
-
- mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
-
-
-
-
-
-
- mMediaRecorder.setVideoFrameRate(20);
-
- mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
-
- mMediaRecorder.setOutputFile
- (Environment.getExternalStorageDirectory()+File.separator+System.currentTimeMillis()+".mp4");
- .....
- mediaRecorder.prepare();
- mediaRecorder.start();
- .....
相同的程序在Android2.3平台上正常运行,在Android4.0上报错。
解决方法:
注释掉设置视频帧率的语句。//mMediaRecorder.setVideoFrameRate(mQuality.framerate);
将setVideoFrameRate去掉之后,如果还出现该错误,可将
mMediaRecorder.setVideoSize(videoWidth, videoHeight);也注释掉
原因:
视频的帧率和视频大小是需要硬件支持的,如果设置的帧率和视频大小,如果硬件不支持就会出现错误。
参考:
http://stackoverflow.com/questions/11249642/mediarecorder-start-failed-19