Error處理: android.media.MediaRecorder.start(Native Method) 報錯:start failed: -19
阿新 • • 發佈:2018-05-14
bsp RM hand apt zygote utf use failed 解決方法
而且也發現,在使用MediaRecorder進行視頻錄制,調用start()方法時報錯,發生spydroid-android測試在android4.0系統上同樣的錯誤,具體錯誤如下:
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上報錯。
解決方法:
註釋掉設置視頻幀率的語句。//mMediaRecorder.setVideoFrameRate(mQuality.framerate);
將setVideoFrameRate去掉之後,如果還出現該錯誤,可將
mMediaRecorder.setVideoSize(videoWidth, videoHeight);也註釋掉
原因:
視頻的幀率和視頻大小是需要硬件支持的,如果設置的幀率和視頻大小,如果硬件不支持就會出現錯誤。
參考:
http://stackoverflow.com/questions/11249642/mediarecorder-start-failed-19
Error處理: android.media.MediaRecorder.start(Native Method) 報錯:start failed: -19