记录音频和同时播放音频 [英] Recording Audio and Playing Audio at the same time

查看:179
本文介绍了记录音频和同时播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我从麦克风录音输入,在某一点上我正在播放声音(同时记录仍在继续)。
现在录像机停止发送记录(mrec.stop()仍然可以使用的),这样​​做的LogCat中条目似乎是:

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.

我对两款手机进行测试,一个是三星Galaxy S,一个是三星Galaxy 3.在Galaxy S的一切都如预期(这是录像还是发生)的作品。
除了规格的两款手机之间的区别是,银河S有2.2.1和银河3 2.2
我算了一下,一个解决方法是重新初始化mediarecorder,但是这使得应用程序的口吃,这是不想要的。

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.

下面是详细信息如何在媒体播放器和mediarecorder进行设置:

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?

任何提示都AP preciated。

Any tips are appreciated.

推荐答案

尝试使用本机基本播放机和录像机......这些都是接近彻底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

好运气

这篇关于记录音频和同时播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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