我尝试在对话框提醒按钮中播放媒体播放器,不知何故它没有工作,但没有错误通知,对话框工作正常,取消按钮,但媒体播放器没有工作
public void TampilanDoa() {
tampilan = new Dialog(DoaHarianActivity.this);
tampilan.setContentView(R.layout.layout_doa);
dengar = tampilan.findViewById(R.id.btdengar);
kembali = tampilan.findViewById(R.id.btkembali);
final MediaPlayer
mp=MediaPlayer.create(this, R.raw.splash);
dengar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
}
});
kembali.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tampilan.cancel();
}
});
tampilan.show();
}
}