File tree Expand file tree Collapse file tree
src/main/java/technobot/listeners Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525
2626import java .net .MalformedURLException ;
2727import java .util .Objects ;
28+ import java .util .concurrent .TimeUnit ;
2829
2930/**
3031 * Module for music player backend and voice channel events.
@@ -50,11 +51,16 @@ public MusicListener() {
5051 * @return string of track length (ex. 2:11)
5152 */
5253 public static @ NotNull String formatTrackLength (long trackLength ) {
53- long msPos = trackLength ;
54- long minPos = msPos / 60000 ;
55- msPos = msPos % 60000 ;
56- int secPos = (int ) Math .floor ((float ) msPos / 1000f );
57- return minPos + ":" + ((secPos < 10 ) ? "0" + secPos : secPos );
54+ long hours = TimeUnit .MILLISECONDS .toHours (trackLength );
55+ long minutes = TimeUnit .MILLISECONDS .toMinutes (trackLength ) - TimeUnit .HOURS .toMinutes (TimeUnit .MILLISECONDS .toHours (trackLength ));
56+ long seconds = TimeUnit .MILLISECONDS .toSeconds (trackLength ) - TimeUnit .MINUTES .toSeconds (TimeUnit .MILLISECONDS .toMinutes (trackLength ));
57+ String time = "" ;
58+ if (hours > 0 ) time += hours + ":" ;
59+ if (minutes < 10 && hours > 0 ) time += "0" ;
60+ time += minutes + ":" ;
61+ if (seconds < 10 ) time += "0" ;
62+ time += seconds ;
63+ return time ;
5864 }
5965
6066 /**
You can’t perform that action at this time.
0 commit comments