if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Going to play " + mp3File);
}
try {
final Media mp3Media = new Media(mp3File.toURI().toURL().toString());
final MediaPlayer mediaPlayer = new MediaPlayer(mp3Media);
synchronized (mediaPlayer) {
mediaPlayer.setAutoPlay(false);
mediaPlayer.setRate(rate);
mediaPlayer.setOnEndOfMedia(new Runnable() {
@Override
public void run() {
synchronized (mediaPlayer) {
mediaPlayer.notifyAll();
}
}
});
mediaPlayer.play();
try {
mediaPlayer.wait(MAXIMUM_PLAY_TIME_PER_MP3);
} catch (InterruptedException e) {
LOGGER.error("Interrupted while waiting for " + mediaPlayer + " to complete play of " + mp3File);
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info(mediaPlayer + " played " + mp3File);