Java Reference
In-Depth Information
audio source by calling player.play() and replaces the play-
large.png with the image pause-large.png . If, however, audio
is currently playing, then the audio is stopped and the image is
replaced back with play-large.png .
The other ImageView instance loads the stop-large.png icon.
When the user clicks on it, it calls its action-handler to first stop
the audio playback by calling player.stop() . Then it toggles
the image for the "play" button back to icon play-large.png .
As mentioned in the introduction, JavaFX will play the MP3 file format on
any platform where the JavaFX format is supported. Anything other than
MP3 must be supported natively by the OS's media engine where the file is
played back. For instance, on my Mac OS, I can play MPEG-4, because it is a
supported playback format by the OS's QuickTime engine.
There's more...
The Media class models the audio stream. It exposes properties to configure the location,
resolves dimensions of the medium (if available; in the case of audio, that information is not
available), and provides tracks and metadata about the resource to be played.
The MediaPlayer class itself is a controller class responsible for controlling playback of
the medium by offering control functions such as play() , pause() , and stop() . It also
exposes valuable playback data including current position, volume level, and status. We will
use these additional functions and properties to extend our playback capabilities in the recipe
Controlling media playback in this chapter.
See also
F Accessing media assets
F Loading and displaying images with ImageView
Playing video with MediaView
The previous recipe shows you how to play audio using the JavaFX Media API. This recipe
builds on the versatility of the Media API and extends the previous recipe, Playing audio with
MediaPlayer , and creates a video player with a few changes to the code.
 
Search WWH ::




Custom Search