Java Reference
In-Depth Information
The next step is to replace the MetadataView with this new VideoView . Listing 9-37 shows the modified code from
the VideoPlayer4 class (formerly AudioPlayer4 ). Instead of creating the MetadataView , we now create the VideoView ,
passing it the mediaModel instance. The VideoView 's view node is then retrieved and set as the center node of the
BorderPane in place of the MetadataView 's view node. That is literally all there is to it!
Listing 9-37. Creating the VideoView and Adding It to the Application's First Page
private Parent createPageOne() {
videoView = new VideoView(mediaModel);
playerControlsView = new PlayerControlsView(mediaModel);
playerControlsView.setNextHandler((ActionEvent arg0) -> {
rootNode.getChildren().setAll(page2);
});
final BorderPane bp = new BorderPane();
bp.setCenter(videoView.getViewNode());
bp.setBottom(playerControlsView.getViewNode());
return bp;
}
One final finishing touch is to change the music note icon on the open button to something more appropriate. We
therefore created a filmstrip icon and replaced the name of the image file used by the button in the application's style sheet.
#openButton {
-fx-graphic: url("resources/filmstrip.png");
}
The final result of our conversion is shown in Figure 9-12 playing a promotional video from Oracle's web site.
All of the controls work exactly the same as they did in the version that played audio files, right down to the equalizer.
You just have to love JavaFX, don't you?
Figure 9-12. The converted video player in action
 
Search WWH ::




Custom Search