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:
[java]
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.audio.AudioNode;
/**
*
-
@author Kabir
*/
public class TestAudioDuration extends SimpleApplication {public static void main(String[] args) {
TestAudioDuration app = new TestAudioDuration();
app.start();
}@Override
public void simpleInitApp() {
//OGG File loading
AudioNode oggNode = new AudioNode(assetManager, “Music/Fire.ogg”, true);
oggNode.setPositional(false);
float oggDuration = oggNode.getAudioData().getDuration();
oggNode.play();
//This prints -1
System.out.println("oggDuration: " + oggDuration);
oggNode.stop();//WAV file loading AudioNode wavNode = new AudioNode(assetManager, "Music/Wind.wav", true); wavNode.setPositional(false); float wavDuration = wavNode.getAudioData().getDuration(); wavNode.play(); //This prints 57.0 System.out.println("wavDuration: " + wavDuration); wavNode.stop();
}
}
[/java]
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.)