Re: How to get the length of wav file?



Here is the code.But here will be some problem if I is called.
public static double getLength(String path) throws Exception {
AudioInputStream stream;
stream = AudioSystem.getAudioInputStream(new URL(path));
AudioFormat format = stream.getFormat();
if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
format = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
format.getSampleSizeInBits() * 2,
format.getChannels(),
format.getFrameSize() * 2,
format.getFrameRate(),
true); // big endian
stream = AudioSystem.getAudioInputStream(format, stream);
}
DataLine.Info info = new DataLine.Info(
Clip.class, stream.getFormat(), ((int)
stream.getFrameLength() * format.getFrameSize()));
Clip clip = (Clip) AudioSystem.getLine(info);
clip.close();
return clip.getBufferSize() / (clip.getFormat().getFrameSize()
* clip.getFormat().getFrameRate());
}

.



Relevant Pages

  • Re: Anyone using HD 720p by camcorder?
    ... crash capturing each clip ... frame of capture. ... how it gets that onto the tape is a mere technical detail. ... Let's assume the tape gets a 1080i stream at 60 or 50fps, ...
    (uk.comp.sys.mac)
  • Re: Storing a sound as an object
    ... The basic unit you need is the Clip class. ... // A stream that will read your data. ... wherever you want to play the Clip: ... On at least one Java implementation, you must stop the clip before you can start it again, even if the audio has actually reached the end ...
    (comp.lang.java.programmer)
  • Re: How is SPI (Service Provider Interface) works?
    ... I tried to write dummy SPI, and load from META-INF/services directory, ... AudioInputStream stream = AudioSystem.getAudioInputStream(new ... Clip clip = AudioSystem.getLine; ...
    (comp.lang.java.programmer)
  • Re: Do all capacitors sound the same.
    ... I presume the above URL sends a 'stream' of some kind. ... My browser simply ... But it has to be said the clip was of impressively high resolution ...
    (uk.rec.audio)
  • RE: Playing a short clip of 1hr recording?
    ... > Is it possible to control the stream of a 1hr audio or video clip to just ... > minutes into the clip until 22 minutes. ... > play anything else and I'd prefer not to have to break up my recordings into ...
    (microsoft.public.windowsmedia.server)