使用AudioRecord录制音频时停止按钮

时间:2022-03-01 19:00:42

At the moment I have the code from this site (link text) working great. In the example on the site it starts the recording for 10 seconds and then immediately plays the audio back in reverse. I have modified the code to start recording when a button is pressed, but can only get it to record for the 10 seconds and then save that file. I want to be able to start the recording by pressing a button and then stop the recording on a different button press. I have an idea that it could be an interrupt to the wait() method of the thread object but have no idea how to implement this. My code is as follows:

目前我从这个网站(链接文本)的代码工作得很好。在网站上的示例中,它开始录制10秒钟,然后立即反向播放音频。我已经修改了代码,当按下按钮时开始记录,但只能记录10秒,然后保存该文件。我希望能够通过按下按钮开始录制,然后在另一个按钮上停止录制。我知道它可能是线程对象的wait()方法的中断,但不知道如何实现它。我的代码如下:

public void onClickRecord(View v){
        text.setText("Recording");
        Thread thread = new Thread(new Runnable() {
            public void run() {
                record();
            }
        });

        thread.start();

        synchronized(this) {
        try {
            wait(10000); //This is the 10 second waiting period while recording
        } 
        catch (InterruptedException e) {
        }
        }

        isRecording = false;

        try {
            thread.join();
        } catch (InterruptedException e) {
        }

    }
    public void onClickStop(View v){
        //Here is what needs to be implemented to stop the recording.
    }

There is quite a bit of code so I have only posted the bits I think are relevant. If any more is needed just ask.

有相当多的代码,所以我只发布了我认为相关的位。如果需要更多,请问。

Thanks.

1 个解决方案

#1


0  

try the AudioRecord Class ! I think that should be helpful.

试试AudioRecord课程吧!我认为这应该是有帮助的。

Also look at AudioCapture here http://developer.android.com/guide/topics/media/index.html

另请参阅AudioCapture http://developer.android.com/guide/topics/media/index.html

#1


0  

try the AudioRecord Class ! I think that should be helpful.

试试AudioRecord课程吧!我认为这应该是有帮助的。

Also look at AudioCapture here http://developer.android.com/guide/topics/media/index.html

另请参阅AudioCapture http://developer.android.com/guide/topics/media/index.html