TinySound icon indicating copy to clipboard operation
TinySound copied to clipboard

Wave Length

Open Tobisaninfo opened this issue 9 years ago • 4 comments

Is it possible to read the length (in seconds) of a wave file? Or is there an work around?

Tobisaninfo avatar Nov 11 '15 13:11 Tobisaninfo

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.

finnkuusisto avatar Dec 02 '15 16:12 finnkuusisto

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.

Tobisaninfo avatar Dec 02 '15 20:12 Tobisaninfo

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;

yousifalyousifi avatar Mar 04 '16 23:03 yousifalyousifi

Thanks, and sorry again, I simply haven't gotten around to adding this feature.

finnkuusisto avatar May 05 '16 15:05 finnkuusisto