AudioNode.getAudioData.getDuration() returns -1

Hello there.

I’ve been looking for a way to get the total length of an ogg sound clip, and getDuration() seemed perfect for the job.
However, whenever I use it, it returns -1, and I’m not quite sure why.

Test case:
package mygame;



  • @author Kabir
    public class TestAudioDuration extends SimpleApplication {

    public static void main(String[] args) {
    TestAudioDuration app = new TestAudioDuration();

    public void simpleInitApp() {
    //OGG File loading
    AudioNode oggNode = new AudioNode(assetManager, “Music/Fire.ogg”, true);
    float oggDuration = oggNode.getAudioData().getDuration();;
    //This prints -1
    System.out.println("oggDuration: " + oggDuration);

     //WAV file loading
     AudioNode wavNode = new AudioNode(assetManager, "Music/Wind.wav", true);
     float wavDuration = wavNode.getAudioData().getDuration();;
     //This prints 57.0
     System.out.println("wavDuration: " + wavDuration);



Using the test case, I found that ogg files don’t return -1, but wav files do.
Since I don’t want to use all wav files in my game (as they are way too large), is there any way around this?

(The reason I want to do this is because my game has a music player of sorts in it, and I want to display the total length of the sound file.)

new AudioNode(assetManager, “Music/Fire.ogg”, true);

Note: true as the last parameter = streaming

Streaming = “we’ll start at the beginning of the file and stream it but we have no idea how long the actual file is.”

1 Like

I can’t believe I overlooked that. I feel silly now.

Thanks for catching my mistake. :smiley:

@navid113 said: ...

I can’t believe I overlooked that. I feel silly now.

Thanks for catching my mistake. :smiley:

Well, it probably didn’t help that wav files can properly report their size even with streaming true… and yeah, it does kind of suck that you can tell the duration of an ogg file when streaming.