1. 程式人生 > >Error處理: android.media.MediaRecorder.start(Native Method) 報錯:start failed: -19

Error處理: android.media.MediaRecorder.start(Native Method) 報錯:start failed: -19

bsp RM hand apt zygote utf use failed 解決方法

spydroid-android測試在android4.0系統上報錯

[html] view plain copy
  1. start failed: -19

而且也發現,在使用MediaRecorder進行視頻錄制,調用start()方法時報錯,發生spydroid-android測試在android4.0系統上同樣的錯誤,具體錯誤如下:

[html] view plain copy
  1. 01-06 14:04:07.790: V/MediaRecorder(13280): prepare
  2. 01-06 14:04:07.790: V/IMediaRecorder(13280): prepare
  3. 01-06 14:04:07.800: V/MediaRecorder(13280): start
  4. 01-06 14:04:07.800: V/IMediaRecorder(13280): start
  5. 01-06 14:04:08.190: E/MediaRecorder(13280): start failed: -19
  6. 01-06 14:04:08.190: W/System.err(13280): java.lang.RuntimeException: start failed.
  7. 01-06 14:04:08.200: W/System.err(13280): at android.media.MediaRecorder.start(Native Method)
  8. 01-06 14:04:08.200: W/System.err(13280): at com.yousee.videocapturedemo.VideoCapturePlus$2.onClick(VideoCapturePlus.java:145)
  9. 01-06 14:04:08.200: W/System.err(13280): at android.view.View.performClick(View.java:3515)
  10. 01-06 14:04:08.200: W/System.err(13280): at android.view.View$PerformClick.run(View.java:14144)
  11. 01-06 14:04:08.200: W/System.err(13280): at android.os.Handler.handleCallback(Handler.java:605)
  12. 01-06 14:04:08.200: W/System.err(13280): at android.os.Handler.dispatchMessage(Handler.java:92)
  13. 01-06 14:04:08.200: W/System.err(13280): at android.os.Looper.loop(Looper.java:148)
  14. 01-06 14:04:08.200: W/System.err(13280): at android.app.ActivityThread.main(ActivityThread.java:4503)
  15. 01-06 14:04:08.200: W/System.err(13280): at java.lang.reflect.Method.invokeNative(Native Method)
  16. 01-06 14:04:08.200: W/System.err(13280): at java.lang.reflect.Method.invoke(Method.java:511)
  17. 01-06 14:04:08.200: W/System.err(13280): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:830)
  18. 01-06 14:04:08.200: W/System.err(13280): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  19. 01-06 14:04:08.200: W/System.err(13280): at dalvik.system.NativeStart.main(Native Method)


MediaRecorder 初始化和設置代碼如下:

[java] view plain copy
  1. .....
  2. mMediaRecorder=new MediaRecorder();
  3. //設置視頻源
  4. mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
  5. //設置音頻源
  6. mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
  7. //設置文件輸出格式
  8. mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  9. //設置視頻編碼方式
  10. mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
  11. //設置音頻編碼方式
  12. mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
  13. //設置視頻高和寬,註意文檔的說明:
  14. //Must be called after setVideoSource().
  15. //Call this after setOutFormat() but before prepare().
  16. //設置錄制的視頻幀率,註意文檔的說明:
  17. //Must be called after setVideoSource().
  18. //Call this after setOutFormat() but before prepare().
  19. mMediaRecorder.setVideoFrameRate(20);
  20. //設置預覽畫面
  21. mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
  22. //設置輸出路徑
  23. mMediaRecorder.setOutputFile
  24. (Environment.getExternalStorageDirectory()+File.separator+System.currentTimeMillis()+".mp4");
  25. .....
  26. mediaRecorder.prepare();
  27. mediaRecorder.start();
  28. .....
[java] view plain copy

相同的程序在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