アラートボックスが表示されているときにサウンド/オーディオを再生しています。
AlertdialogのPositiveまたはNegativeボタンを押した場合に対応したいのですが、それまでに音声が完成していない場合は、音声の再生を止めてほしいです。
この特定の状態を処理するにはどうすればよいですか?
コード:
AlertDialog.Builder alertdialog = new AlertDialog.Builder(
Activity.this);
alertdialog.setTitle("Title ");
alertdialog.setMessage("The MEssage ");
LayoutInflater layoutinf= LayoutInflater.from(Activity.this);
final View view = layoutinf.inflate(R.layout.layoutfile, null);
alertdialog.setView(view);
alertdialog.setPositiveButton("Button1",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
//do something
}
});
alertdialog.show();
MediaPlayer mp = MediaPlayer.create(this, R.raw.file_to_play);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});