Incorporating media into a JavaFX application
JavaFX provides the means to play media files in the javafx.scene.media
package. It supportsthe following media formats:
- MP3
- MP4
- AIFF
- WAV
- FLV
You can find all the latestdetails in the JavaDoc: https://docs.oracle.com/javase/10/docs/api/javafx/scene/media/package-summary.html.
Adding audio clips
The simplest form of media is an AudioClip
, which works best for short sounds such as a button click. Note that AudioClip
is not dedicated to longer audio or music sequences for the following reasons:
- It holds the whole clip in memory.
- It doesn't provide any API for choosing the playback time.
The AudioClip
API is very simple; it doesn't require any extra objects and is recommended for short sound effects. For longer audio clips, use the Media
class described in the next section.
The following formats are supported by the AudioClip
class:
- MP3
- AIFF containing uncompressed PCM
- WAV containing uncompressed PCM
- MPEG-4 multimedia container with Advanced Audio Coding (AAC)...