Search code examples
javaaudiomp3javasoundjavax.sound.sampled

Exception in reading an MP3 file through AudioSystem.getAudioInputStream(file)


I am trying to read an MP3 file through class javax.sound.sampled.AudioSystem but I am getting an UnsupportedAudioFileException. My code trying to read the audio file looks like:-

AudioInputStream audioInputStream = 
    AudioSystem.getAudioInputStream(file);

I am getting the following exception:-

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

Does AudioSystem class not support mp3 format? If not then what formats does it supports? Or Am I doing some mistake here?


Solution

  • No it doesn't support MP3 (hence the UnsupportedAudioFileException). The supported files are quite basic (WAV and that sort of thing), so for any advanced codecs you'll need separate libraries.