Example usage for javafx.scene.media MediaPlayer getTotalDuration

List of usage examples for javafx.scene.media MediaPlayer getTotalDuration

Introduction

In this page you can find the example usage for javafx.scene.media MediaPlayer getTotalDuration.

Prototype

public final Duration getTotalDuration() 

Source Link

Document

Retrieves the total playback duration including all cycles (repetitions).

Usage

From source file:AudioPlayer3.java

private void updatePositionSlider(Duration currentTime) {
    if (positionSlider.isValueChanging())
        return;//from w ww .  j av  a 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());
    }
}

From source file:AudioPlayer3.java

private Node createControlPanel() {
    final HBox hbox = new HBox();
    hbox.setAlignment(Pos.CENTER);// ww  w . j  ava2  s . co m
    hbox.setFillHeight(false);

    final Button playPauseButton = createPlayPauseButton();

    final Button seekStartButton = new Button();
    seekStartButton.setId("seekStartButton");
    seekStartButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            seekAndUpdatePosition(Duration.ZERO);
        }
    });

    final Button seekEndButton = new Button();
    seekEndButton.setId("seekEndButton");
    seekEndButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            final MediaPlayer mediaPlayer = songModel.getMediaPlayer();
            final Duration totalDuration = mediaPlayer.getTotalDuration();
            final Duration oneSecond = Duration.seconds(1);
            seekAndUpdatePosition(totalDuration.subtract(oneSecond));
        }
    });

    hbox.getChildren().addAll(seekStartButton, playPauseButton, seekEndButton);
    return hbox;
}