gpt4 book ai didi

android - 将进度条与计时器同步

转载 作者:行者123 更新时间:2023-11-29 22:30:08 25 4
gpt4 key购买 nike

我想在单击按钮时与音频文件同时更新我的​​ ProgressBar。我还使用了根据音频文件的长度(以秒为单位)运行的计时器。

我已经配置了定时器,它根据音频文件的长度很好地增加,但我的 ProgressBar 不工作。它给了我 NumberFormatException。

我的代码: MyCount 类扩展了 CountDownTimer { 私有(private)诠释我的计数;

        public MyCount(long millisInFuture, long countDownInterval) 
{
super(millisInFuture, countDownInterval);
}

public void onFinish()
{
//timeDisplay.setText("done!");
}
public void onTick(long millsIncreasing)
{

mycount++;
mystring = formatTime(mycount*1000);
myText.setText(mystring);
pBar.setProgress(Integer.parseInt(mystring)); (*****)
pBar.setProgress(1000 * pBar.getProgress());
/*String myString1 = mystring.substring(0, mystring.lastIndexOf(":")).trim();
String myString2 = mystring.substring(mystring.lastIndexOf(":")+1, mystring.length()).trim();*/

我在括号中显示星星的那一行出现了异常。任何人都可以帮助我,谢谢大卫

最佳答案

由于您的函数返回的字符串“12:34”(中间有 :)不是 Integer.parse 可以解析的数字格式。

你应该保留一个变量来保存文件时间长度的值(以秒为单位)

int fileLength

然后在你的函数中:

public void onTick(long millsIncreasing) 
{
int progress = (int)Math.round(millsIncreasing / fileLength) * 100;
Bar.setProgress(progress);

这是假设 millsIncreasing 参数是 ms。处理到此为止。

关于android - 将进度条与计时器同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4364085/

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