Hi here is a snipit of code…the idea is that it runs for 20 secs then at 5 seconds before 0 it plays one sound then at end of countdown plays the next…but it is just playing the end and skipping the 5 sec mark…I have tried playing with it but can’t get it to work.
Any ideas?
//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();
}
};
It’s cause your :
Is in the same ‘thread’ as your Timer. You should just do somthing like :
Or something like that 😀
Cause you cant decrease your Timer and play sound at same time ! 🙂