JFXperience.com

My thoughts on JavaFX, Java, RIA and other stuff …
  • rss
  • Home
  • About
  • Contact
  • RadioFX
  • TelemeterFX

Playing Streaming MP3

Yannick | August 23, 2009

For 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();
Comments
No Comments »
Categories
JavaFX
Tags
JavaFX, mp3, sound, streaming, webradio
Comments rss Comments rss
Trackback Trackback

Navigation

  • General
  • Java
  • JavaFX

Search

Archives

  • November 2009
  • September 2009
  • August 2009

Links

  • Blogroll
    • JFXStudio
    • LearnJavaFX
    • SteveOnJava
  • JavaFX
    • JavaFX
    • jfxtras
    rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox