Example usage for javafx.scene.media MediaMarkerEvent getMarker

List of usage examples for javafx.scene.media MediaMarkerEvent getMarker

Introduction

In this page you can find the example usage for javafx.scene.media MediaMarkerEvent getMarker.

Prototype

public Pair<String, Duration> getMarker() 

Source Link

Document

Retrieves the marker the event represents.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    final Label markerText = new Label();
    StackPane.setAlignment(markerText, Pos.TOP_CENTER);

    String workingDir = System.getProperty("user.dir");
    final File f = new File(workingDir, "../media/omgrobots.flv");

    final Media m = new Media(f.toURI().toString());

    final ObservableMap<String, Duration> markers = m.getMarkers();
    markers.put("Robot Finds Wall", Duration.millis(3100));
    markers.put("Then Finds the Green Line", Duration.millis(5600));
    markers.put("Robot Grabs Sled", Duration.millis(8000));
    markers.put("And Heads for Home", Duration.millis(11500));

    final MediaPlayer mp = new MediaPlayer(m);
    mp.setOnMarker(new EventHandler<MediaMarkerEvent>() {
        @Override/*from  w w w  . j  a  va2  s. c  om*/
        public void handle(final MediaMarkerEvent event) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    markerText.setText(event.getMarker().getKey());
                }
            });
        }
    });

    final MediaView mv = new MediaView(mp);

    final StackPane root = new StackPane();
    root.getChildren().addAll(mv, markerText);
    root.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            mp.seek(Duration.ZERO);
            markerText.setText("");
        }
    });

    final Scene scene = new Scene(root, 960, 540);
    final URL stylesheet = getClass().getResource("media.css");
    scene.getStylesheets().add(stylesheet.toString());

    primaryStage.setScene(scene);
    primaryStage.setTitle("Video Player 2");
    primaryStage.show();

    mp.play();
}