Im trying to get the duration of a Music, in libgdx
Im not talking about :
getPosition();
What I want is the Duration of the music. (in seconds)
Thanks
To be clear by "duration" you mean the total time the music would play without looping.
I don't think the Libgdx sound APIs expose this (the lowest common denominator sound API across desktop, Android and Web is pretty low ...).
You may be able to get this information out of the files you're loading into system, though (e.g., if they're wav or mp3 files there should be APIs to query their duration).
Its an old question but I will give my answer for the future visitors
To get the duration of a music file you can use the gdx-audio extension.
FileHandle file=Gdx.files.internal(filepath);
FileHandle external=Gdx.files.external("mygame/"+filepath);
if(!external.exists())file.copyTo(external); //copy the file to the external storage
Mpg123Decoder decoder = new Mpg123Decoder(external);
System.out.println("name:"+filepath+" duration:"+decoder.getLength());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With