Q:

Android Mediaplayer - based on seekbar progress update the elapsed time of audio in textview

Using Mediaplayer to play the audio file. 
Everything works fine but the elapsed time of audio need to be updated in textview. 
textview.setText(mediaplayer.getCurrentPosition()/100000.0).toString();

This gives the double value but if the end time is more than a minute and the elapsed time is 1minute it shows 0:60... but it should as 1:00...
Is there anyother way to show the elapsed time based on seekbar progress? 
Thanks. 

A:

This works- Answer taken from another post :
How do I correctly display the position/duration of a MediaPlayer? 
DateFormat works for dates, not for time intervals.  So if you get a position of 1 second, the data format interprets this as meaning that the date/time is 1 second after the beginning the calendar. 

private String getTimeString(long millis) {
    StringBuffer buf = new StringBuffer();

    int hours = millis / (1000*60*60);
    int minutes = ( millis % (1000*60*60) ) / (1000*60);
    int seconds = ( ( millis % (1000*60*60) ) % (1000*60) ) / 1000;

    buf
        .append(String.format("%02d", hours))
        .append(":")
        .append(String.format("%02d", minutes))
        .append(":")
        .append(tring.format("%02d", seconds));

    return buf.toString();
}

And then do something like

totalTime.setText(getTimeString(duration));
currentTime.setText(getTimeString(position));

