Java Reference
In-Depth Information
F
The controls
—as before, the control buttons consist of image icons displayed by
instances of
ImageView
. The custom component loads six icons that represent
functionalities such as reverse, play, pause, fast-forward, volume up, and volume down.
The play and pause icons, assigned to
ImageView
instance with
id = "playCtrl"
,
use the same logic from previous media playback recipes (consult the recipe
Playing
audio with MediaPlayer
for details). Let's see how the others work:
To fast-forward and reverse, we use
ImageView
instances with
id="reverseCtrl"
and
id="ffwdCtrl"
respectively. When
the user clicks on these icons, the code adds one percent of the
total duration to (or subtracts from)
mediaPlayer.currentTime
property. This has the effect of moving the playhead in the desired
direction.
To adjust the volume is even simpler. We use instances of
ImageView with
id="volup"
and
id="voldn"
to control the
volume. When the user clicks on the icon, it sets
mediaPlayer.
volume
to the desired ratio. To increase the volume we add
0.4
to
the current volume. To decrease the volume, we subtract
0.4
from
the current volume level.
See also
F
Chapter 2—Create your own custom node
F
Loading and displaying images with ImageView
F
Playing audio with MediaPlayer
F
Playing video with MediaView



