I want to read the content of the .mp3
file into a byte array(Not including header and metadata). For this purpose I'm using following code.
File myFile = new File("C:\\Users\\Kaushal28\\Desktop\\a.mp3");
byte[] samples;
AudioInputStream is = AudioSystem.getAudioInputStream(myFile);
DataInputStream dis = new DataInputStream(is); //So we can use readFully()
try{
AudioFormat format = is.getFormat();
samples = new byte[(int)(is.getFrameLength() * format.getFrameSize())];
dis.readFully(samples);
}
finally{
dis.close();
}
Here is the link where it is posted: Here.
I executed this code with a mp3 file of a song. but got following exception:
javax.sound.sampled.UnsupportedAudioFileException: could not get audio input stream from input file
I've also tried this with .au file type, but got same exception.
For this I searched on Internet and found this: This SO link.
It says that all wav formats are not supported by java. Is it also true for .mp3 file formats? Or any other reasons due to which I'm getting this exception?