Android : MediaPlayer Duration currentTime and endTime

on Thursday, January 29, 2015


Android MediaPlayer duration currentTime and endTime, still showing, like this:



currentTime - 0m:4s
endTime - 4m: 9s


but want to show like this:



currentTime - 00m:04s
endTime - 04m:09s


code looks like this:



endTimeField.setText(String.format("%dm:%ds",
TimeUnit.MILLISECONDS.toMinutes((long) finalTime),
TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) finalTime)))
);
startTimeField.setText(String.format("%dm:%ds",
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) startTime)))
);

......................

private Runnable UpdateSongTime = new Runnable() {
public void run() {
startTime = mediaPlayer.getCurrentPosition();

startTimeField.setText(String.format("%dm:%ds",
TimeUnit.MILLISECONDS.toMinutes((long) startTime),
TimeUnit.MILLISECONDS.toSeconds((long) startTime) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.
toMinutes((long) startTime)))
);
seekbar.setProgress((int)startTime);
myHandler.postDelayed(this, 100);
}
};

0 comments:

Post a Comment