Android的AudioRecord和MediaRecorder并行 [英] AudioRecord and MediaRecorder Android parallele

查看:152
本文介绍了Android的AudioRecord和MediaRecorder并行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在我的应用程序和音频记录MediaRecorder中同时使用.一个注册我的脚本,另一个注册我的脚本,以显示具有输入信号幅度的声音输入.当我同时使用但独立使用时,我的应用程序崩溃了.那么您有我可以同时使用的解决方案吗?

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)

推荐答案

许多基于Android设备的平台将打开的音频输入流的数量限制为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.

您可以使用AudioRecord记录原始PCM,并将该数据用于将其写入文件(如果这就是注册我的脚本"的意思),也可以用作可视化工具的输入.缺点是,如果您想保存压缩的音频(例如mp3),则需要自己在应用中处理编码.

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.

这篇关于Android的AudioRecord和MediaRecorder并行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆