Example usage for javafx.util Duration subtract

List of usage examples for javafx.util Duration subtract

Introduction

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

Prototype

public Duration subtract(Duration other) 

Source Link

Document

Subtract other Duration instance from this instance to return a new Duration instance.

Usage

From source file:AudioPlayer3.java

private Node createControlPanel() {
    final HBox hbox = new HBox();
    hbox.setAlignment(Pos.CENTER);//from www  . j  a  v  a  2 s.c  o 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;
}