3

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

Code:

public static void main(String[] args) throws URISyntaxException {
        new JFXPanel(); //init jfx library
        String u = "http://91.121.164.186:8050";
        Media m=null;
        try {
            m = new Media(u);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        MediaPlayer player = new MediaPlayer(m);
        System.out.println("play");
        player.play();
        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 ?

Burkhard
  • 14,596
  • 22
  • 87
  • 108
Gravian
  • 957
  • 2
  • 11
  • 20

2 Answers2

1

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

http://docs.oracle.com/javafx/2/media/EmbeddedMediaPlayer.zip

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

Community
  • 1
  • 1
ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
  • As i said it's working with local files. The url is from .pls file so it should be good. How to convert it to media component ? – Gravian May 13 '14 at 15:33
  • You can use the media types specified here as a direct media to the MediaPlayer http://docs.oracle.com/javafx/2/api/javafx/scene/media/package-summary.html#SupportedMediaTypes – ItachiUchiha May 14 '14 at 07:19
0

"http://91.121.164.186:8050" is a website, (HTML document), not a audio file. You need to download an audio file, something that the player knows what to do with.

DirkyJerky
  • 1,130
  • 5
  • 10