开发者

Synchronizing the Progress Bar with the Timer

I want to update my ProgressBar simultaneously with the audio file on clicking the Button. I had also used the timer which runs according to the length of the audio file which is in seconds.

I have configured the Timer and it is nicely increasing according to the length of the audio file but my ProgressBar is not working. It gives me NumberFormatException.

My Code: class MyCount extends CountDownTimer { private int mycount;

        public MyCount(long millisInFuture, long countDownInterval) 
        {
          supe开发者_开发技巧r(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();*/

I am getting the Exception on the line where I have shown the Stars in the BRACKET. Can anybody please help me, Thanks david


Since your function is returning a String "12:34" (with the : in middle) that is not a number format that Integer.parse can parse.

You should keep a variable which will hold the value of the file time length (in seconds)

int fileLength

then in your function:

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

this is assuming that the millsIncreasing parameter is the ms. processed so far.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜