3

I have the following code:

String fileName="D:/downloads/song.mp3";
File soundFile = new File(fileName);
AudioInputStream audioInputStream = null;
try {
    audioInputStream = AudioSystem.getAudioInputStream(soundFile);
} catch (Exception ex) {
   ex.printStackTrace();
}

But the code raises the following exception:

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

How can I solve this problem?

javanna
  • 59,145
  • 14
  • 144
  • 125
Rajesh Agrawal
  • 484
  • 2
  • 5
  • 18

2 Answers2

1

Sounds like you're missing an MP3 codec. See this thread for possible solutions. They mention a Java sound mailing list that might know more - http://java.sun.com/products/java-media/sound/list.html

I82Much
  • 26,901
  • 13
  • 88
  • 119
1

The answers are to be found in the JavaSound tag info. page (a tag I added to the question). Look particularly to the sections on:

  1. Service Provider Interface
  2. Java Sound Capabilities
  3. MP3 decoding support

The first describes how the JavaSound system (and in fact many Java based services) are provided to apps. The 2nd should explain why your code fails for MP3. The 3rd will offer a way to add MP3 support to JavaSound.


BTW - what does any of this have to do with ?

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433