嗨,这里是一段代码......这个想法是它运行 20 秒,然后在 0 之前的 5 秒播放一个声音,然后在倒计时结束时播放下一个......但它只是播放结束并跳过5 秒标记...我试过玩它,但无法让它工作。
有任何想法吗?
//Counter 2
final CountDownTimer counter2 = new CountDownTimer(20000 , 1000) {
public void onTick(long millisUntilFinished) {
mCounter2TextField.setText(" " + formatTime(millisUntilFinished));
long timeLeft = millisUntilFinished / 1000;
if (timeLeft == 5000)
playAlertSound(R.drawable.sound1);
}
public void onFinish() {
start();
playSound();
}
public void playSound() {
MediaPlayer mp = MediaPlayer.create(getBaseContext(), (R.drawable.sound2));
mp.start();
}
};