TinySound
TinySound copied to clipboard
Wave Length
Is it possible to read the length (in seconds) of a wave file? Or is there an work around?
Sorry I never got back to you. I don't actually have a workaround for you I'm afraid. This is probably a feature I should add, so I'll mark this as an enhancement.
If you need the feature right now, you could probably load a javax.sound.sampled.Clip and ask for the length. Sorry I don't have a better answer for you right now.
At the moment right now I use the AudioInputStream an compute the length this the framesize und framerate. But is is a kind of annoying to do it that way. I am looking forward to this feature in a further build.
Here's the code:
AudioInputStream audio = AudioSystem.getAudioInputStream(musicFile);
AudioFormat audioFormat = audio.getFormat();
float frameRate = audioFormat.getFrameRate();
long frameLength = audio.getFrameLength();
float durationInSeconds = frameLength/frameRate;
Thanks, and sorry again, I simply haven't gotten around to adding this feature.