1

I am having some problems with this code, I am trying to play the sound file but it is not working.

import java.io.*;
import java.net.URL;
import javax.sound.sampled.*;

public class DiscoMusic
{

  public static void main(String[] args) throws Exception
  {
    URL url = new URL("http://www.lecons-guitare.com/Audio/Backingtracks/Stayin_alive.mp3");
    AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
    Clip clip = AudioSystem.getClip();
    clip.open(audioIn);
    clip.start();
  }
}
Stefan
  • 1,433
  • 1
  • 19
  • 30
Michael
  • 39
  • 3
  • have you checked these out: http://stackoverflow.com/questions/6045384/playing-mp3-and-wav-in-java and http://stackoverflow.com/questions/657921/how-to-stream-mp3-using-pure-java and http://stackoverflow.com/questions/5344729/java-play-mp3-by-url – Yohanes Khosiawan 许先汉 Sep 12 '14 at 03:13

1 Answers1

1

According to the JavaSound info. page.

MP3 decoding support

The Java Sound API does not support many formats of sampled sound internally. In a 1.6.0_24 Oracle JRE getAudioFileTypes() will generally return {WAVE, AU, AIFF}. An MP3 decoder at least, is close by. The mp3plugin.jar of the Java Media Framework supports decoding MP3s.

I can vouch for that information since I've successfully loaded MP3s using Java Sound and the MP3 SPI (& also wrote the info. page ;) ). The JMF installer download is becoming hard to find, but you can get the mp3plugin.jar direct from where I put it for use in JWS apps.

Community
  • 1
  • 1