Re: How to get the length of wav file?
- From: "lgj573@xxxxxxxxx" <lgj573@xxxxxxxxx>
- Date: 16 May 2006 23:12:33 -0700
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());
}
.
- Follow-Ups:
- Re: How to get the length of wav file?
- From: Eric Schwartz
- Re: How to get the length of wav file?
- References:
- How to get the length of wav file?
- From: lgj573@xxxxxxxxx
- Re: How to get the length of wav file?
- From: bdj
- How to get the length of wav file?
- Prev by Date: Re: Naming consultation request (proposed Geo::ReadGRIB)
- Next by Date: Net::Google 502 Bad gateway errors
- Previous by thread: Re: How to get the length of wav file?
- Next by thread: Re: How to get the length of wav file?
- Index(es):
Relevant Pages
|