Libgdx gets music duration

I am trying to get the duration of music in libgdx

Im not talking about:

getPosition(); 

What I want is the duration of the music. (in seconds)

thanks

+6
source share
3 answers

To be understood in terms of duration, you mean the total playing time of music without a loop.

I don't think Libgdx APIs display this (the lowest common denominator APIs on the desktop, Android and Web are pretty low ...).

You can get this information from files that you upload to the system, though (for example, if they are wav or mp3 files, there must be an API to request their duration).

+7
source

His old question, but I will give my answer to 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()); 
+3
source

if ur wants to stop the music whenever he wants using

 music.stop(); 

or pause music using

 music.pause(); 

or for other tasks, refer to this link https://github.com/libgdx/libgdx/wiki/Streaming-music

-2
source

All Articles