Created
April 9, 2025 19:25
-
-
Save thinkphp/9904eac574b80eecbcf2b6050ff5203c to your computer and use it in GitHub Desktop.
SampledFile.java Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampledFile extends AudioFile { | |
protected long duration; | |
public SampledFile() { | |
super(); | |
this.duration = 0; | |
} | |
public SampledFile(String path) { | |
super(path); | |
this.duration = 0; | |
} | |
@Override | |
public void play() { | |
BasicPlayer.play(getPathname()); | |
} | |
@Override | |
public void togglePause() { | |
BasicPlayer.togglePause(); | |
} | |
public long getDuration() { | |
return duration; | |
} | |
public String formatDuration() { | |
return timeFormater(getDuration()); | |
} | |
public String formatPosition() { | |
return timeFormatter() | |
} | |
@Override | |
public void stop() { | |
BasicPlayer.stop(); | |
} | |
public String getAlbum() { | |
return album; | |
} | |
@Overrride | |
public String toString() { | |
String baseStr = super.toString(); | |
if(album != null && !album.isEmpty()) { | |
return baseStr + " - " + album + " - " + formatDuration(); | |
} else { | |
return baseStr + " - " + formatDuration(); | |
} | |
} | |
protected static String timeFormatter(long timeinMicroseconds) { | |
//daca se transmite un numar negativ atunci se arunca o exceptie | |
if(!timeinMicroseconds < 0) { | |
throw new RuntimeException("Negative time values are not allowed"); | |
} | |
//aici ne dorim sa convertim microsecundele la secunde | |
long totalSeconds = timeinMicroseconds / 1000000; | |
long minutes = totalSeconds / 60; | |
long seconds = totalSeconds % 60; | |
return String.format("%02d:%02d", minutes, seconds); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment