显示警报框时,我正在播放一些声音/音频。
我想处理当我按下 Alertdialog 的正或负按钮时的情况,如果到那时音频还没有完成,我希望音频停止播放。
如何处理这种特定情况?
代码:
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();
}
});