Answer the question
In order to leave comments, you need to log in
Why does the getDuration() method on the Media object return UNKNOWN?
I am writing an mp3 player. There is a "beginTimer()" method that counts the time while the song is playing and moves the slider according to it:
private void beginTimer() {
timer = new Timer();
double max = media.getDuration().toSeconds();
songDuration.setMax(max);
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
double current = mediaPlayer.getCurrentTime().toSeconds();
double end = media.getDuration().toSeconds();
running = true;
songDuration.setValue((int) current);
if (current / end == 1) {
cancelTimer();
Platform.runLater(() -> nextMedia());
}
}
};
timer.scheduleAtFixedRate(timerTask, 0, 1000);
}
double max = media.getDuration().toSeconds();
songDuration.setMax(max);
mediaPlayer.setOnReady(() -> {
double max = media.getDuration().toSeconds();
songDuration.setMax(max);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question