Error处理: android.media.MediaRecorder.start(Native Method) 报错:start failed: -19【转】
本文转载自:http://blog.csdn.net/netwalk/article/details/17686993
Error处理: android.media.MediaRecorder.start(Native Method) 报错:start failed: -19
spydroid-android测试在android4.0系统上报错
- start failed: -19
而且也发现,在使用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);
- //设置视频高和宽,注意文档的说明:
- //Must be called after setVideoSource().
- //Call this after setOutFormat() but before prepare().
- //设置录制的视频帧率,注意文档的说明:
- //Must be called after setVideoSource().
- //Call this after setOutFormat() but before prepare().
- 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