gpt4 book ai didi

android - 为什么 millisUntilFinished 无法检测到准确的 CountDownTimer 间隔?

转载 作者:太空宇宙 更新时间:2023-11-03 13:05:48 25 4
gpt4 key购买 nike

大家好,CountDownTimer 有一个相当小但令人讨厌的问题。目前我将间隔设置为 1000。我正在尝试检测我的

中剩余的毫秒数
onTick()

方法。这样我就可以在还剩 20 秒、还剩 10 秒等时使用 Text To Speech。好吧,如果我使用:

//Speak when 20 seconds left
if (millisUntilFinished == 20000) {
tts.speak("You have 20 seconds left.", TextToSpeech.QUEUE_FLUSH, null);
}

计时器无法准确检测到 20000 毫秒。

所以我不得不求助于:

//Speak when 20 seconds left
if (millisUntilFinished < 20999) {
if (millisUntilFinished > 19999) {
tts.speak("You have 20 seconds left.", TextToSpeech.QUEUE_FLUSH, null);
}
}

问题在于,有时文本转语音会在此间隔期间出现两次。有没有什么方法可以准确检测毫秒数,这样我就不必使用大于或小于?

最佳答案

Is there any way to detect the milliseconds exactly so I dont have to use greater than or less than?

当然不是。 Android 不是 RTOS。时间将是近似值,仅仅是因为主应用程序线程可能在任何给定时刻都忙于其他任务。

关于android - 为什么 millisUntilFinished 无法检测到准确的 CountDownTimer 间隔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4824068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com