Playing Streaming MP3
Yannick | August 23, 2009For a webradio client I’m writing, I wanted to play an mp3 stream.
The following code plays an online mp3 file without any problems but refused to play the infinite mp3 stream:
player = MediaPlayer {
media : Media {
source: streamUrl
}
}
player.play();
After spending some time on google looking for the result, I came across a solution in Java that uses the Javazoom JLayer player to process the mp3 stream.
While I was implementing this, a colleague came up with a much better solution… Just set the repeatCount property of the javafx MediaPlayer to “REPEAT_FOREVER” and it will play an infinite mp3 stream. I never thought of this myself because it looked logical to me that this property is just used to identify how many times you want to play a certain audio file. But anyway, it works great now and makes it really easy to create a webradio client.
So the final code is:
player = MediaPlayer {
repeatCount: MediaPlayer.REPEAT_FOREVER
media : Media {
source: streamUrl
}
}
player.play();





