Reputation: 494
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?
Upvotes: 3
Views: 4898
Reputation: 168795
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:
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 audio-recording?
Upvotes: 1
Reputation: 27326
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
Upvotes: 1