Java Reference
In-Depth Information
Table 9-1. Media Formats Supported by JavaFX
File Extension
Type
Format
Mime Type
.mp3
Audio
MP3: MPEG-1, 2, 2.5 audio with ID3 v2.3, v2.4 metadata
audio/mpeg
.aif, .aiff
Audio
Audio Interchange File Format: uncompressed audio
audio/x-aiff
.wav
Audio
Waveform Audio Format: uncompressed audio
audio/x-wav
.aac, .m4a
Audio
MPEG-4 multimedia container with Advanced Audio Coding (AAC) audio
audio/aac
.fxm
Video
FX Media: VP6 video with MP3 audio
video/x-javafx
.flv
Video
Flash Video: VP6 video with MP3 audio
video/x-flv
.mp4
Video
MPEG-4 multimedia container with H.264/AVC (Advanced Video
Coding) video compression
video/mp4
FXM is the “native” JavaFX video format. It consists of VP6 encoded video and MP3 audio, a combination that is
also used in Flash Video (FLV) files. An FLV container can host several different options for video and audio encoding
other than VP6 and MP3. Therefore, it is not correct to say that JavaFX can play any FLV file. However, the VP6/MP3
combination is very common, so it is fair to say that JavaFX should be able to play most FLV files that can be found on
the Internet. FLV video is widely supported by tools from Adobe and others, so you should have no trouble converting
or authoring video in this format.
As of JavaFX 2.1, support for H.264 is available. JavaFX now supports MPEG-4 multimedia with H.264 video
and AAC audio.
Working with Audio Clips
In the earliest versions of JavaFX, there was no way to play low-latency audio. This much-needed feature became
available in version 2.0 using the new AudioClip class. Audio clips are not suitable for large or lengthy sounds because
the audio data associated with these sounds are decompressed and stored completely in memory. If you need to play
a song or other lengthy audio file, you should use a Media object instead, which is discussed in the next section.
An AudioClip is ideal for playing short sounds in response to user actions in a game or other rich-media
application. An AudioClip instance is constructed by passing a URI string as the only parameter to the constructor. This
URI can point to a resource on the Internet, the local file system, or within the jar file by using the http: , file: , and
jar: schemes, respectively. Once an AudioClip is constructed, you can adjust several properties that affect the playback
of the clip, such as the volume, playback rate, panning, and balance. Calling its play method will begin playback of an
AudioClip . You can call the play method repeatedly to begin multiple overlapping playbacks of a given clip.
There are actually three overloaded versions of the play method in the AudioClip class. Calling the method with
no arguments will use the current properties of the AudioClip instance for the playback. There is also a variant of the
play method that takes a volume argument, which allows you to override the volume of the clip for that playback only.
The final variant of the play method allows you to specify the volume, balance, rate, pan, and priority of that playback.
Specifying these parameters as arguments of the play methods does not cause them to be saved permanently; they
are a one-time-only override of the AudioClip 's instance data. There is also a stop method that stops all playback of
the AudioClip .
Listing 9-1 illustrates the simple steps required to create and play an AudioClip . This source code is part of the
BasicAudioClip example project in the Chapter09 directory of the topic's source code.
 
 
Search WWH ::




Custom Search