AudioRecord and MediaRecorder Android parallele

倖福魔咒の 提交于 2019-12-12 21:42:02

问题


I have to use in my application and audiorecord MediaRecorder same time. One register my scripts and the other for displaying the sound input with the amplitudes of the input signal. My application crash when I use simultaneously but independently it works fine. So do you have a solution that I can use at the same time???

Trace logCat :
10-16 22:02:08.675: E/MediaRecorder(9007): start failed: -1
10-16 22:02:08.675: W/System.err(9007): java.lang.RuntimeException: start failed.
10-16 22:02:08.675: W/System.err(9007):     at android.media.MediaRecorder.start(Native Method)
10-16 22:02:08.675: W/System.err(9007):     at com.ax.audio_recorder.viewlvlmicro.SoundMeter.start(SoundMeter.java:40)
10-16 22:02:08.675: W/System.err(9007):     at com.ax.audio_record.MainActivity.start(MainActivity.java:177)
10-16 22:02:08.675: W/System.err(9007):     at com.ax.audio_record.MainActivity.access$0(MainActivity.java:173)
10-16 22:02:08.680: W/System.err(9007):     at com.ax.audio_record.MainActivity$3.onClick(MainActivity.java:154)
10-16 22:02:08.680: W/System.err(9007):     at android.view.View.performClick(View.java:2538)
10-16 22:02:08.680: W/System.err(9007):     at android.view.View$PerformClick.run(View.java:9152)
10-16 22:02:08.680: W/System.err(9007):     at android.os.Handler.handleCallback(Handler.java:587)
10-16 22:02:08.680: W/System.err(9007):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-16 22:02:08.680: W/System.err(9007):     at android.os.Looper.loop(Looper.java:130)
10-16 22:02:08.680: W/System.err(9007):     at android.app.ActivityThread.main(ActivityThread.java:3691)
10-16 22:02:08.680: W/System.err(9007):     at java.lang.reflect.Method.invokeNative(Native Method)
10-16 22:02:08.680: W/System.err(9007):     at java.lang.reflect.Method.invoke(Method.java:507)
10-16 22:02:08.680: W/System.err(9007):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
10-16 22:02:08.680: W/System.err(9007):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
10-16 22:02:08.680: W/System.err(9007):     at dalvik.system.NativeStart.main(Native Method)

回答1:


Many platforms that Android devices are based on limit the number of open audio input streams to 1, which is causing an exception when you try to create another one before closing the first.

You could record raw PCM with an AudioRecord and use that data both for writing it to a file (if that's what you mean by "register my scripts") and as input for your visualizer. The downside is that if you want to save the audio compressed (e.g. mp3) you'll need to handle the encoding yourself in your app.



来源:https://stackoverflow.com/questions/12934157/audiorecord-and-mediarecorder-android-parallele

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!