Search code examples
androidandroid-mediaplayertextviewandroid-seekbar

how to update audio progress to minutes


currently in my app the media plays correctly and the textView also updates perfectly.. in seconds 0:00

below is the code for onProgressChanged

@Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
            seekBarHint.setVisibility(View.VISIBLE);
            int x = (int) Math.ceil(progress / 1000f);

            if (x < 10)
                seekBarHint.setText("0:0" + x);
            if (x > 10)
                seekBarHint.setText("0:" + x);
            }

the above code is working as it should..

i want the textView timer to update to 1:00 after it plays for 0:59 seconds

i tried to update the code as below :

@Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
        seekBarHint.setVisibility(View.VISIBLE);
        int x = (int) Math.ceil(progress / 1000f);

        if (x < 10)
            seekBarHint.setText("0:0" + x);
        if (x > 10)
            seekBarHint.setText("0:" + x);

    if (x >= 60 &&  x < 70)
           x=0;
           seekBarHint.setText("1:0" + x);
    if (x > 70)
           seekBarHint.setText("1:" + x);
}

but i get the textView as "1.00" from the start. and after 0.59 seconds.. it shows as 1:060 1:061 and so on...

How to update the value of x to 0 after the media plays for 0.59 seconds..

in short

i am getting the textView value as

0:00 to 0:59 then 0:60 ...

i want it as

0:00 to 0:59 then 1:00


Solution

  • If x is time in seconds, then this simple line should work.

    seekBarHint.setText(String.format(secondsToString(x))
    
    private String secondsToString(int pTime) {
            return String.format("%02d:%02d", pTime / 60, pTime % 60);
        }