0

I'm trying to do a simple mp3 player,everything is perfect, just I have one problem I can't do (Play) the streaming radio mp3, where i do button 'play' i get this message:

Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Stereo, LittleEndian, 
    Signed, 16000.0 frame rate, FrameSize=32768 bits
    Failed to realize: com.sun.media.PlaybackEngine@c88f97
    Error: Unable to realize com.sun.media.PlaybackEngine@c88f97

this is my code :

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    String radiourl = direccionurl.getText();
    URL url;
    try {
        url = new URL(radiourl);

        openFile(url);
    } catch (MalformedURLException ex) {
        Logger.getLogger(VentanaInicio.class.getName()).log(Level.SEVERE, null, ex);
    }

   p.start();
}             

public  void openFile(URL url){

    try{
      p = Manager.createPlayer(url);
      p.start();
    }catch (Exception o){
      o.printStackTrace();
    }
}
Jonas
  • 121,568
  • 97
  • 310
  • 388
cleo
  • 165
  • 1
  • 11
  • This has nothing to do with Swing other than being in a Swing application (which is not causing your error in the least). Swing tag removed. – Hovercraft Full Of Eels May 30 '12 at 23:14
  • thanks for your answer, but can you explaine me how can i play a streaming radio mp3 en Java?? for example this url : http://broadcast.infomaniak.net/tsfjazz-high.mp3 – cleo May 30 '12 at 23:20

1 Answers1

1

I also needed to write an audio player recently, and found an old, but good article with lots of sample code at http://onjava.com/pub/a/onjava/2004/08/11/javasound-mp3.html

I wrote a fairly simple player based on the information there. Up until now, I had only used it to play files, but I plugged your URL in, did a URL.openStream(), and sent it off to the player. Worked great.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
  • hello still didt worked, the programe ist not give me any error, but it looks as if this gasp: this is my new code for play URL(http) AudioInputStream audioIn = AudioSystem.getAudioInputStream(url); Clip clip = AudioSystem.getClip(); clip.open(audioIn); clip.start(); – cleo May 31 '12 at 13:07
  • I found the Clip class to be somewhat limited and unreliable. Take a look at the rawplay() method about half-way down the second page at the url that I posted above. That's what worked for me. – GreyBeardedGeek Jun 01 '12 at 20:12