0
目前我从本网站获得的代码(link text)效果很好。在网站上的示例中,它开始录制10秒钟,然后立即反向播放音频。我修改了代码以便在按下按钮时开始录制,但只能让它录制10秒钟然后保存该文件。我希望能够通过按下一个按钮开始录制,然后在不同的按钮按下时停止录制。我有一个想法,它可能是一个中断的线程对象的wait()方法,但不知道如何实现这一点。我的代码如下:使用AudioRecord录制音频时的停止按钮
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.
}
有相当多的代码,所以我只发布了我认为相关的位。如果还有其他需要问的话。
谢谢。