Play audio stream with JavaFX


I'm trying to make simple audio player with JavaFX Mediaplayer component. All local files are fine but i want also implement internet radio.


public static void main(String[] args) throws URISyntaxException {
        new JFXPanel(); //init jfx library
        String u = "";
        Media m=null;
        try {
            m = new Media(u);
        } catch (MalformedURLException e) {
        MediaPlayer player = new MediaPlayer(m);
        player.setVolume(new Double(1));


When I run it like this there is no errors but there is no audio. What's wrong ? What are other posibilities to play radio stream in Java ?

5/13/2014 1:07:39 PM

In your current example I can see two errors,

  1. You are trying to run a JAVAFX component on a non-Javafx thread, which will result in error. Try running your program inside the start method. Please go through How to use JavaFX MediaPlayer correctly?

  2. The URL you are trying to access must be a Media Compoenent

Try going through this extremely great example on Javafx Media

N.B. The example has lot more data than your require, but its a great example !

5/23/2017 11:59:37 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow