Example usage for javafx.util Duration toMillis

List of usage examples for javafx.util Duration toMillis

Introduction

In this page you can find the example usage for javafx.util Duration toMillis.

Prototype

public double toMillis() 

Source Link

Document

Returns the number of milliseconds in this period or Double.POSITIVE_INFINITY if the period is INDEFINITE or NaN if the period is UNKNOWN.

Usage

From source file:AudioPlayer3.java

private String formatDuration(Duration duration) {
    double millis = duration.toMillis();
    int seconds = (int) (millis / 1000) % 60;
    int minutes = (int) (millis / (1000 * 60));
    return String.format("%02d:%02d", minutes, seconds);
}

From source file:AudioPlayer3.java

private void updatePositionSlider(Duration currentTime) {
    if (positionSlider.isValueChanging())
        return;/*from   w ww . j a  va 2s.c o m*/

    final MediaPlayer mediaPlayer = songModel.getMediaPlayer();
    final Duration total = mediaPlayer.getTotalDuration();

    if (total == null || currentTime == null) {
        positionSlider.setValue(0);
    } else {
        positionSlider.setValue(currentTime.toMillis() / total.toMillis());
    }
}