Java Reference
In-Depth Information
Once the media player object is in a ready state, a MediaView instance is created
to display the media. The following code creates a MediaView object to be placed in-
to the scene graph to display video content:
// Lazy init media viewer
if (mediaView == null) {
mediaView = new MediaView();
mediaView.setMediaPlayer(mediaPlayer);
mediaView.setX(4);
mediaView.setY(4);
mediaView.setPreserveRatio(true);
mediaView.setOpacity(.85);
mediaView.setSmooth(true);
mediaView.fitWidthProperty().bind(scene.widthProperty().subtract(220));
mediaView.fitHeightProperty().bind(scene.heightProperty().subtract(30));
// make media view as the second node on the scene.
root.getChildren().add(1, mediaView);
}
// sometimes loading errors occur, print error when this
happens
mediaView.setOnError((MediaErrorEvent event1) -> {
event1.getMediaError().printStackTrace();
});
mediaView.setMediaPlayer(mediaPlayer);
event.setDropCompleted(success);
event.consume();
});
Whew! You are finally finished with the scene's drag-dropped EventHandler .
Up next is pretty much the rest of the media button controls, which are similar to the
code at the end of Recipe 16-1. The only difference is a single instance variable named
paused of type Boolean that denotes whether the video was paused. The following
Search WWH ::




Custom Search