Java Reference
In-Depth Information
#backButton {
-fx-shape: "M 3,0 L 12,0 Q 13,0 13,1 L 13,9 Q 13,10 12,10 L 3,10 1,5";
-fx-font-size: 12pt;
-fx-alignment: center-right;
}
.eqSlider {
-fx-background-radius: 5;
-fx-background-color: #222, #888, black;
-fx-background-insets: 0, 1 0 0 1, 1;
-fx-padding: 2 10;
}
.eqSlider .thumb {
-fx-background-image: url("resources/thumb.png");
-fx-padding: 12;
}
.eqSlider:vertical .track{
-fx-padding: 5;
}
.spectrumBar {
-fx-background-radius: 5;
-fx-background-color: #222, #888, black;
-fx-background-insets: 0, 1 0 0 1, 1;
-fx-padding: 2 10;
}
MediaPlayer
Wrap-Up
Playing media files over the Internet happens automatically with the JavaFX media API. All you have to do is point
a
Media
object to an HTTP resource and attach it to a
MediaPlayer
with
autoPlay
set to true. If, however, you are
interested in monitoring the progress of the download buffer, you can use the
bufferProgressTime
property in the
MediaPlayer
class. When data are loaded from a stream or from disk, the amount of time those data will take to play is
calculated and this time is regularly updated as the value of
bufferProgressTime
. By binding to this property, you can
receive these updates and effectively monitor the media's buffer.
The final two
MediaPlayer
properties we discuss are the
rate
and
currentRate
properties. Calling
setRate
allows you to control the rate of the playback. Passing a parameter of 1.0 will cause playback to proceed at the normal
rate. A parameter of 2.0 would cause your media to be played at twice the normal rate. You can pass any value between
0.0 and 8.0. The
currentRate
property always reflects the actual rate of playback, regardless of the value of the rate
property. For example, if playback is currently stalled,
currentRate
will be 0.0 even though
rate
may be set to 4.0.
Playing Video
From an API standpoint, playing video instead of audio is as simple as wrapping a
MediaPlayer
with a
MediaView
and adding the
MediaView
to the scene graph. Listing 9-31 shows how this is done. You simply point a
Media
object at
a valid source (a Flash movie in this case) and wrap it with an auto-playing
MediaPlayer
, which, in turn, is wrapped
with a
MediaView
. The final step is to add the
MediaView
to the scene and set the size of the scene to match the size of
the movie.
Search WWH ::
Custom Search