Reading Mp3 File
994393Mar 2 2013 — edited Mar 4 2013I am reading Mp3 file and want to convert in desired audio format.I am trying Following code.when i read file using "in" while loop run 469 times.while when i run using din i am getting 4601.So why is it so.
i m totally confused here.plz help!!!!!
My code is
import javax.sound.sampled.*;
import java.io.*;
public class Demo
{
public static void main(String args[])
{
try {
File file = new File("D:\\aa.mp3");
AudioInputStream in= AudioSystem.getAudioInputStream(file);
AudioInputStream din = null;
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
44100,
16,
baseFormat.getChannels(),
baseFormat.getChannels() * 2,
baseFormat.getSampleRate(),
false);
byte[] data = new byte[4096];
din = AudioSystem.getAudioInputStream(decodedFormat, in);
Demo n =new Demo();
int nBytesRead = 0, nBytesWritten = 0;
int x=0;
while (nBytesRead != -1)
{
x++;
nBytesRead = din.read(data, 0, data.length);
System.out.println(x);
}
}
catch (Exception e)
{
//Handle exception.
}
}
public SourceDataLine getLine(AudioFormat audioFormat) throws LineUnavailableException
{
SourceDataLine res = null;
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
res = (SourceDataLine) AudioSystem.getLine(info);
res.open(audioFormat);
return res;
}
}