使用MediaRecorder录音,正常流程没有问题,如果一个进程录音的时候,另一个进程再录音程序就崩溃了,而且是在start()的时候崩溃的,讨厌java的很多函数没有返回值,如 prepare()、 start()等,我加了异常处理如下:
try {
mRecorder.prepare();//预期准备
Log.i(TAG, "recorder.prepare()" );
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
Log.i(TAG,e.getMessage());
e.printStackTrace();
return false;
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i(TAG,e.getMessage());
e.printStackTrace();
return false;
}
try{
mRecorder.start(); //开始刻录
}catch (IllegalStateException e) {
// TODO Auto-generated catch block
Log.i(TAG,e.getMessage());
e.printStackTrace();
return false;
}
我对java不是很熟,不知道这样使用异常有没有问题? 当一个进程再录音时,另一个进程启动时,我想得到mic的状态,类似于getStatuse() 之类的函数,请问大家有没有好的办法? 谢谢!
出错信息如下:
04-26 02:23:59.241: E/MediaRecorder(3197): start failed: -1
04-26 02:23:59.251: D/AndroidRuntime(3197): Shutting down VM
04-26 02:23:59.251: W/dalvikvm(3197): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-26 02:23:59.462: E/AndroidRuntime(3197): FATAL EXCEPTION: main
04-26 02:23:59.462: E/AndroidRuntime(3197): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.provider.Telephony.SMS_RECEIVED (has extras) } in [email protected]
04-26 02:23:59.462: E/AndroidRuntime(3197): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:905)
04-26 02:23:59.462: E/AndroidRuntime(3197): at android.os.Handler.handleCallback(Handler.java:587)
04-26 02:23:59.462: E/AndroidRuntime(3197): at android.os.Handler.dispatchMessage(Handler.java:92)
04-26 02:23:59.462: E/AndroidRuntime(3197): at android.os.Looper.loop(Looper.java:123)
04-26 02:23:59.462: E/AndroidRuntime(3197): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-26 02:23:59.462: E/AndroidRuntime(3197): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 02:23:59.462: E/AndroidRuntime(3197): at java.lang.reflect.Method.invoke(Method.java:521)
04-26 02:23:59.462: E/AndroidRuntime(3197): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-26 02:23:59.462: E/AndroidRuntime(3197): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)