Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

audio file duration--help pls

saran185saran185 Member Posts: 23
hi...

can anyone help me to get the audio file duration . i used the below code.
but i get frame length as 0 and duration as 0. im using javax.sound.* api.. can anyone help me in fixing the bud pls..
[code]
try {
File f1 = new File(filename);
AudioInputStream fis =
AudioSystem.getAudioInputStream(f1);
System.out.println("File AudioFormat: " + fis.getFormat());
AudioInputStream ais = AudioSystem.getAudioInputStream(
AudioFormat.Encoding.PCM_SIGNED,fis);
AudioFormat af = ais.getFormat();
int frmlength = (int)ais.getFrameLength();
System.out.println("AudioFormat: " + af.toString());

int frameRate = (int)af.getFrameRate();
System.out.println("Frame Rate: " + frameRate);
int frameSize = af.getFrameSize() *2;
System.out.println("Frame Size: " + frameSize);

System.out.println("Frame Length " + frmlength);


SourceDataLine line = AudioSystem.getSourceDataLine(af);
line.addLineListener(new MyLineListener());

line.open(af);
int bufSize = line.getBufferSize();
System.out.println("Buffer Size: " + bufSize);
int nTotalMS = bufSize/(frameSize*frameRate);
System.out.println("Frame Duration " + nTotalMS);
line.start();

byte[] data = new byte[bufSize];
int bytesRead;

while ((bytesRead = ais.read(data,0,data.length)) != -1)
line.write(data,0,bytesRead);

line.drain();
line.stop();
line.close();
} catch (Exception e) {
System.out.println(e);
}
[/code]
Sign In or Register to comment.