异常信息:
11-10 11:22:42.539: I/AudioRecordPermission(10402): remindWithResult:false
11-10 11:22:42.549: E/MediaRecorder(10402): start failed: -22
11-10 11:22:42.549: D/AndroidRuntime(10402): Shutting down VM
11-10 11:22:42.549: W/dalvikvm(10402): threadid=1: thread exiting with uncaught exception (group=0x416ade18)
11-10 11:22:42.579: E/AndroidRuntime(10402): FATAL EXCEPTION: main
11-10 11:22:42.579: E/AndroidRuntime(10402): Process: *******, PID: 10402
11-10 11:22:42.579: E/AndroidRuntime(10402): java.lang.RuntimeException: start failed.
11-10 11:22:42.579: E/AndroidRuntime(10402): at android.media.MediaRecorder.start(Native Method)
11-10 11:22:42.579: E/AndroidRuntime(10402): at **********************
11-10 11:22:42.579: E/AndroidRuntime(10402): at **********************
11-10 11:22:42.579: E/AndroidRuntime(10402): at **********************
11-10 11:22:42.579: E/AndroidRuntime(10402): at android.os.Handler.dispatchMessage(Handler.java:102)
11-10 11:22:42.579: E/AndroidRuntime(10402): at android.os.Looper.loop(Looper.java:136)
11-10 11:22:42.579: E/AndroidRuntime(10402): at android.app.ActivityThread.main(ActivityThread.java:5336)
11-10 11:22:42.579: E/AndroidRuntime(10402): at java.lang.reflect.Method.invokeNative(Native Method)
11-10 11:22:42.579: E/AndroidRuntime(10402): at java.lang.reflect.Method.invoke(Method.java:515)
11-10 11:22:42.579: E/AndroidRuntime(10402): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
11-10 11:22:42.579: E/AndroidRuntime(10402): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
11-10 11:22:42.579: E/AndroidRuntime(10402): at dalvik.system.NativeStart.main(Native Method)
相关代码:
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setAudioChannels(AudioFormat.CHANNEL_CONFIGURATION_MONO);
这种异常在部分手机上会出现,这些手机的共同点是在开始录音的时候会提示你去允许录音权限,但是不管点允许还是拒绝都会出这个错误
后来发现把mMediaRecorder.setAudioChannels(AudioFormat.CHANNEL_CONFIGURATION_MONO);这行代码去掉就可以了,原因暂时未知,可能是参数的问题,又兴趣的可以多尝试几个参数