MediaRecorder 类设置音频源出现问题 - setAudioSource() - 不支持的参数
我是 Android 开发新手,我有下一个问题。
我正在使用 MediaRecorder 类来仅录制来自麦克风的音频。我按照官方网站中指示的步骤操作: http://developer. android.com/reference/android/media/MediaRecorder.html
所以我有一个方法可以初始化和配置 MediaRecorder 对象以开始录制。这里有代码:
this.mr = new MediaRecorder();
this.mr.setAudioSource(MediaRecorder.AudioSource.MIC);
this.mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
this.mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
this.mr.setOutputFile(this.path + this.fileName);
try {
this.mr.prepare();
} catch (IllegalStateException e) {
Log.d("Syso", e.toString());
e.printStackTrace();
} catch (IOException e) {
Log.d("Syso", e.toString());
e.printStackTrace();
}
当我在模拟器中执行此代码时,多亏了 logcat,我可以看到方法 setAudioSource(MediaRecorder.AudioSource.MIC) 在调用时给出了下一个错误(带有标签 audio_ipunt):
ERROR/audio_input(34): unsupported parameter: x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value
ERROR/audio_input(34): VerifyAndSetParameter failed
然后当调用方法prepare()时,我再次收到另一个错误:
ERROR/PVOMXEncNode(34): PVMFOMXEncNode-Audio_AMRNB::DoPrepare(): Got Component OMX.PV.amrencnb handle
如果我通过调用方法start()开始记录...我收到很多消息说:
AudioFlinger(34):RecordThread: buffer overflow
然后...在停止并释放之后,....我可以看到已经创建了一个文件,但似乎没有很好地记录。不管怎样,如果我在真实设备中尝试这个,我可以毫无问题地录制,但我无法播放我刚刚录制的内容。
我想关键就在于我之前提到的这些错误。我该如何修复它们?有什么建议或帮助吗?
I'm new in Android development and I have the next question/problem.
I'm playing around with the MediaRecorder class to record just audio from the microphone. I'm following the steps indicated in the official site: http://developer.android.com/reference/android/media/MediaRecorder.html
So I have a method that initializes and configure the MediaRecorder object in order to start recording. Here you have the code:
this.mr = new MediaRecorder();
this.mr.setAudioSource(MediaRecorder.AudioSource.MIC);
this.mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
this.mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
this.mr.setOutputFile(this.path + this.fileName);
try {
this.mr.prepare();
} catch (IllegalStateException e) {
Log.d("Syso", e.toString());
e.printStackTrace();
} catch (IOException e) {
Log.d("Syso", e.toString());
e.printStackTrace();
}
When I execute this code in the simulator, thanks to logcat, I can see that the method setAudioSource(MediaRecorder.AudioSource.MIC) gives the next error (with the tag audio_ipunt) when it is called:
ERROR/audio_input(34): unsupported parameter: x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value
ERROR/audio_input(34): VerifyAndSetParameter failed
And then when the method prepare() is called, I get the another error again:
ERROR/PVOMXEncNode(34): PVMFOMXEncNode-Audio_AMRNB::DoPrepare(): Got Component OMX.PV.amrencnb handle
If I start to record bycalling the method start()... I get lots of messages saying:
AudioFlinger(34):RecordThread: buffer overflow
Then...after stop and release,.... I can see that a file has been created, but it doesn't seem that it been well recorderd. Anway, if i try this in a real device I can record with no problems, but I CAN'T play what I just recorded.
I gues that the key is in these errors that I've mentioned before. How can I fix them? Any suggestion or help??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
模拟器在录音方面存在很多问题。可以说它不起作用。您最好的选择是在真实设备中尝试您的代码!
The simulator has lots of issues with the audio recording. Lets say that it doesn't work. Your best bet is try your code in a real device!!!
参考:http://developer.android.com/guide/topics/media /audio-capture.html
Ref: http://developer.android.com/guide/topics/media/audio-capture.html
好吧,我对 Android 编程还很陌生,但我会告诉你们我到目前为止所学到的知识。这里的一些答案表明他们在真实设备(主要是 Galaxy S)上遇到问题,并且模拟器/虚拟设备也无法工作。嗯,我从 Google 上了解到,虚拟设备目前不支持录音。这可能仍然准确,也可能不准确。然而,一位经验丰富的 Android 程序员告诉我,就硬件而言,没有理由相信设备之间存在相似之处,因为如今 Android 可在许多设备上使用。此外,每个 Android 操作系统都经过轻微修改,以专门满足每个设备的需求,因此即使 Droid 和 Droid X 可能都运行 Android Froyo,Froyo 的版本也略有不同。话虽如此,也许 Galaxy S 的麦克风通话方法或其他方面略有不同。我的测试设备恰好是 MotoDroid,所以我无法确定这一点,抱歉。但我希望这能有所帮助!
编辑:
我的错,模拟器确实支持录音。
well, i'm fairly new at this android programming, but I'll give you guys what I've learned so far about that. A few of the answers on here state that they are having issues on real devices, mostly the galaxy S, and the emulator/virtual device isn't working either. Well, I read from Google that the virtual device doesn't support audio recording right now. That may or may not be still accurate. However, a significantly more experienced android programmer told me that there is no reason to believe that there are similarities between devices as far as hardware goes, since android is available on so many devices nowadays. Also, each android OS is modified very slightly to cater specifically to each device, so even though the Droid and the Droid X may both be running Android Froyo, the versions of Froyo are slightly different. All that being said, maybe the Galaxy S has a slightly different call method for the microphone or something. My test device happens to be a MotoDroid, so I can't be sure about that, sorry. But I hope this helps a little bit!
EDIT:
my bad, the emulator does support audio recording.