-
Notifications
You must be signed in to change notification settings - Fork 2
Using AudioListener
Ralph Niemitz edited this page May 21, 2017
·
2 revisions
An AudioListener
can be attached to an instance of Audio
in order to listen to certain events.
It is a functional interface, that means you can use Lambda expressions on it.
The only method inside of it is called update
and takes an AudioEvent
as parameter.
The important thing of the event is the instance of AudioEvent.Type
inside of it.
Example:
try {
Audio audio = new StreamedAudio("music1.mp3");
audio.addAudioListener(event -> {
if(event.getType() == AudioEvent.Type.REACHED_END) {
System.out.println("The audio reached its end...");
event.getAudio().close();
}
});
audio.open();
audio.play();
} catch(AudioException exception) {
exception.printStackTrace();
}