Java Reference
In-Depth Information
much of the UI code into convenience functions so you will be able to focus on the
Media APIs without getting lost in the UI code. The rest of the recipes in this chapter
consist of adding simple features to the JavaFX basic media player created in this re-
cipe. This being said, the code snippets in the following recipes will be brief, consisting
only of the necessary code for each new desired feature.
It is important to note that the JavaFX media player supports various media
formats. The supported formats are as follows:
AIFF
FXM, FLV
HLS (*)
MP3
MP4
WAV
For a complete summary of the supported media types, see the online documenta-
tion at http://docs.oracle.com/javase/8/javafx/api/javafx/
scene/media/package-summary.html .
Just like the audio player created in the last recipe, the JavaFX basic video player
has the same basic media controls, including stop, pause, and play. In addition to these
simple controls, you've added new capabilities such as seeking and full-screen mode.
When playing a video you'll need a view area
( javafx.scene.media.MediaView) to show it. You also create a slider control
to monitor the progress of the video, which is located at the lower-left portion of the
application shown in Figure 16-3 . The slider control allows the users to seek backward
and forward through the video. One last bonus feature is enabling the video to become
full screen by double-clicking the application window. To restore the window, users re-
peat the double-click or press Escape.
To quickly get started, let's jump into the code. After setting the stage in the
start() method, you create a black semitransparent background by calling the
createBackground() method ( applicationArea ). Next, the at-
tachMouseEvents() method is invoked to set up the EventHandler s so they
can enable the users to drag the application window around the desktop. Another
EventHandler to be attached to the scene will allow the users to switch to full-
screen mode. A conditional is used to check for a double-click in the application win-
dow in order to invoke full-screen mode. Once the double-click is performed, the
Search WWH ::




Custom Search