Class MediaPlayer have methods such as getCurrentPosition will return the value in milliseconds.
Heres the problem, when I get the value I use the class TimeUnit.MILLISECONDS.toSeconds and toMinutes, but I dont get the right values.
The values I is
xx:xzy and y is changing each seconds and when reaching 9 the z changes.
I need in xx:xx
This should work for you:
public static void main(String[] args) {
int yourms = 3636600;
int split[] = splitTime(yourms);
System.out.println(yourms + " ms = " + split[0] + " minutes and " + split[1] + " seconds.");
}
public static int[] splitTime(int ms) {
int ss = ms / 1000;
int mm = ss / 60;
ss = ss - (mm * 60);
return new int[]{mm, ss};
}
Example Output:
3636600 ms = 60 minutes and 36 seconds.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.