現時点では、このサイトのコード (リンク テキスト) がうまく機能しています。サイトの例では、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.
}
かなりの量のコードがあるので、関連すると思われるビットのみを投稿しました。さらに必要な場合は、お尋ねください。
ありがとう。