Hey all, so there is a rather small but annoying problem with the CountDownTimer.. Currently I have an interval set to 1000. And I am trying to detect the amount of milliseconds left in my
onTick()
method. So that I can use Text To Speech when there are 20 seconds left, 10 seconds left, etc. Well if I use:
//Speak when 20 seconds left
if (millisUntilFinished == 20000) {
tts.speak("You have 20 seconds left.", TextToSpeech.QUEUE_FLUSH, null);
}
The timer is not able to detect the 20000 milliseconds exactly.
So I have to resort to using:
//Speak when 20 seconds left
if (millisUntilFinished < 20999) {
if (millisUntilFinished > 19999) {
tts.speak("You have 20 seconds left.", TextToSpeech.QUEUE_FLUSH, null);
}
}
The problem with that is that sometimes the text to speech will come on twice during that interval. Is there any way to detect the milliseconds exactly so I dont have to use greater than or less than?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…