使用MediaRecorder录音,正常流程没有问题,如果一个进程录音的时候,另一个进程再录音程序就崩溃了,而且是在start()的时候崩溃的,讨厌java的很多函数没有返回值,如 prepare()、 start()等,我加了异常处理如下:
- Java code
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)
04-26 02:23:59.462: E/AndroidRuntime(3197): at dalvik.system.NativeStart.main(Native Method)
04-26 02:23:59.462: E/AndroidRuntime(3197): Caused by: java.lang.RuntimeException: start failed.
04-26 02:23:59.462: E/AndroidRuntime(3197): at android.media.MediaRecorder.start(Native Method)
04-26 02:23:59.462: E/AndroidRuntime(3197): at com.TS.RcdMediaCtrl.StartRecord(RcdMediaCtrl.java:70)
04-26 02:23:59.462: E/AndroidRuntime(3197): at com.TS.SnsReceiver.onReceive(SnsReceiver.java:53)
04-26 02:23:59.462: E/AndroidRuntime(3197): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:892)
------解决方案--------------------
Audiorecoder按理说应该是可以支持多个的。只不过是从audiofliger里把数据多转一份出来,可以做samplerate的转换。audiotrack可以有多个同时向audiofliger送数据的,这种思想在recorder上应该也是逆向可行的。
------解决方案--------------------
我也纠结这个问题啊
------解决方案--------------------
这个说法在Android技术文档中有却确定么?!
public void start ()
Since: API Level 1 Begins capturing and encoding data to the file specified with setOutputFile(). Call this after prepare().
Since API level 13, if applications set a camera via setCamera(Camera), the apps can use the camera after this method call. The apps do not need to lock the camera again. However, if this method fails, the apps should still lock the camera back. The apps should not start another recording session during recording.