Error处理( android.media.MediaRecorder.start(Native Method) 报错:start failed: -19)
枕上从妨一夜睡,灯前读尽十年诗。这篇文章主要讲述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系统上报错
[html]
view plain
copy
- start failed: -19
而且也发现,在使用MediaRecorder进行视频录制,调用start()方法时报错,发生spydroid-android测试在android4.0系统上同样的错误,具体错误如下:
[html] view plain copy
- 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 初始化和设置代码如下:
[java] view plain copy
- .....
- 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上报错。
【Error处理( android.media.MediaRecorder.start(Native Method) 报错:start failed: -19)】解决方法:
注释掉设置视频帧率的语句。//mMediaRecorder.setVideoFrameRate(mQuality.framerate);
将setVideoFrameRate去掉之后,如果还出现该错误,可将
mMediaRecorder.setVideoSize(videoWidth, videoHeight); 也注释掉
原因:
视频的帧率和视频大小是需要硬件支持的,如果设置的帧率和视频大小,如果硬件不支持就会出现错误。
参考:
http://stackoverflow.com/questions/11249642/mediarecorder-start-failed-19
推荐阅读
- android MediaRecorder start failed(-38)
- Androidstudio 编译慢这样的体验肯定很多人都有!!!
- no appropriate service handler found,修改数据库的最大连接数,默认150
- Android编译时的问题,使用的API大于最低版本
- Android - 问题解决之ScrollView嵌套ListView时总是自动滑动到ListView顶部的问题
- Android - 问题解决之EditText自动获取焦点问题
- virtualenv和virtualenvwrapper安装和配置
- Hybrid App 开发模式
- Win10系统我的电脑属性打开不了怎样办?