同时录制音频和播放音频
在我的应用程序中,我正在录制来自麦克风的输入,并且在某个时刻我正在播放声音(同时录制仍在进行中)。 现在录音机“停止”录音(mrec.stop() 可能仍会被使用),LogCat 条目似乎是:
07-03 18:40:34.811: INFO/AudioHardwareALSA(2179): Output standby called!!. Turn off PCM device.
我正在两部手机上进行测试,一部是三星 Galaxy S,一部是三星 Galaxy 3。在 Galaxy S 上,一切都按预期进行(即录制仍在进行)。 这两款手机除了规格之外的区别在于,Galaxy S 有 2.2.1,Galaxy 3 有 2.2 我认为解决方法是再次初始化媒体记录器,但这会使应用程序卡顿,这是不希望的。
以下是如何设置媒体播放器和媒体记录器的更多信息:
void Init()
{
mp = MediaPlayer.create(getContext(), R.raw.pop);
mrec = new MediaRecorder();
mrec.setAudioSource(MediaRecorder.AudioSource.MIC);
mrec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
[..]
mrec.setOutputFile(audiofile.getAbsolutePath());
mrec.prepare();
mrec.start();
}
void Event()
{
mp.start();
}
为什么录制“停止”?有什么办法可以让停车停止吗?这是期望的行为吗?我怎样才能找出问题所在?
任何提示表示赞赏。
In my application i am recording input from the microphone and at a certain point i am playing a sound (while the recording is still going).
Now the recorder "stops" to record (mrec.stop() may still be used), the LogCat entry for this seems to be:
07-03 18:40:34.811: INFO/AudioHardwareALSA(2179): Output standby called!!. Turn off PCM device.
I am testing on two phones, one is a Samsung Galaxy S and one is a Samsung Galaxy 3. On the Galaxy S everything works as expected (which is that the recording still takes place).
The difference between the two phones besides the specs is that the Galaxy S has 2.2.1 and the Galaxy 3 2.2
I figured, that a workaround would be to initialize the mediarecorder again, but this makes the application stutter, which is not wanted.
Here is more information how the mediaplayer and the mediarecorder are set up:
void Init()
{
mp = MediaPlayer.create(getContext(), R.raw.pop);
mrec = new MediaRecorder();
mrec.setAudioSource(MediaRecorder.AudioSource.MIC);
mrec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
[..]
mrec.setOutputFile(audiofile.getAbsolutePath());
mrec.prepare();
mrec.start();
}
void Event()
{
mp.start();
}
Why does the recording "stop"? Is there a way to halt the stop? Is this the desired behaviour? How can i find out what's wrong?
Any tips are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用本机基本播放器和录音器...这些可以通过 AudioTrack 类和其他相关 api(如音频格式)访问。使用它们,您可以在块或缓冲区(显式字节数组)中记录和播放 pcm 音频数据,并使用循环将缓冲区写入您想要的任何内容。可能这样可以同时进行重新编码和播放
祝你好运
Try using the native basic player and recorder ... These are accessible thorough AudioTrack class and other related apis like audio format. Using them you can record and play pcm audio data in chunks or buffer (explicit byte arrays) and use a loop to write the buffer to Anything you want. May be that would allow to do recoding and playing simultaneously
Good luck