我有停机计数器的代码:
CountDownTimer CountdownTimer = new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
txttime.setText( millisUntilFinished / 1000);
play_sound();
}
public void onFinish(){
timeout_stage(); //call an activity
}
}.start();
我的问题是,当我调用CountdownTimer.cancel();
这两条线时应该停止:
txttime.setText( millisUntilFinished / 1000);
play_sound();
但是现在,将文本设置为 txttime 会停止,但不会播放声音!为什么?
这是我的 play_sound();
public void play_sound(){
MediaPlayer mp;
mp = MediaPlayer.create(MainActivity.this, R.raw.success);
mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
mp.start();
}