B4J Question MP3 Duration

derez

Expert
Licensed User
Longtime User
I'm trying to get a MP3 file's duration using the medialayer's method, but gets NaN :
B4X:
Dim uri As String = File.GetUri("E:\Music\Amit Erez","Please.mp3")
mp.Initialize("mp",uri)
mp.Play
Log(mp.Duration)

The file plays so the path is OK.
 

Daestrum

Expert
Licensed User
Longtime User
You can try
B4X:
...
asJO(mp).RunMethodJO("getTotalDuration",null).RunMethod("toSeconds",null)
...
Sub asJO(o as JavaObject) as JavaObject
return o
End Sub
Also maybe try it before mp.play
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User

Thanks, it is the same.
I tried with a Tag editor and I can see the time there...
 
Last edited:
Upvote 0

derez

Expert
Licensed User
Longtime User
It will return the same result (in seconds instead of milliseconds) as the Duration property.

Nan means that the duration is not yet known.

You can use CallSubPlus to check the duration 100ms after you initialize mp.

Thank you, now I get it !
The min delay is 36 ms.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…