1

I am trying to run a sound file in Java using this code:

  public class Audio3
  {
     public static void main(String[] args) throws Exception
      { 
        URL soundFile =new URL( 
          "http://everyayah.com/data/Ghamadi_40kbps/audhubillah.mp3");
        AudioInputStream ais = AudioSystem.getAudioInputStream(soundFile);
        AudioPlayer.player.start(ais);
      }
  }

I am getting this exception

javax.sound.sampled.UnsupportedAudioFileException: 
    could not get audio input stream from input URL

Any idea what could be the reason?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user1226162
  • 1,972
  • 8
  • 27
  • 42

1 Answers1

3

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
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Issue resolved, but if i use Google App Engine , i get this javax.sound.sampled.AudioInputStream is not supported by Google App Engine's Java runtime environment : Any Idea – user1226162 Apr 26 '12 at 08:58
  • *"Google App Engine"* The GAE is an almost entirely separate matter. I have no experience with it. If you want to pursue that, you'd be best asking a new question and adding the GAE tag to grab the attention of the people that know it. – Andrew Thompson Apr 26 '12 at 09:07