We can load the audio files with extensions like .mp3,.wav and .aifff by using JavaFX Media API. We can also play the audio in HTTP live streaming format. It is the new feature introduced in JavaFX 8 which is also known as HLS.
Playing audio files in JavaFX is simple. For this purpose, we need to instantiate javafx.scene.media.Media class by passing the audio file path in its constructor. The steps required to be followed in order to play audio files are described below.
The Media File can be located on a web server or on the local file system. SetAutoPlay() method is the short-cut for setting the setOnReady() event handler with the lambda expression to handle the event.
In the following example, the audio file located at "/home/javatpoint/Downloads/test.mp3" in our computer is played upon executing this application.