B4J Question Video file metadata - length

Damjan

Member
Hi there,

Is it possible to retrieve video file metadata in B4J? Length would be just enough for me.

Kind regards,
Damjan.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub CreateMedia(Dir As String, FileName As String) As ResumableSub
   Dim media As JavaObject
   media.InitializeNewInstance("javafx.scene.media.Media", Array(File.GetUri(Dir, FileName)))
   Dim player As JavaObject
   player.InitializeNewInstance("javafx.scene.media.MediaPlayer", Array(media))
   Dim millis As Double
   For i = 1 To 20
       Sleep(1000)
       Dim state As String = player.RunMethod("getStatus", Null)
       If state = "READY" Then
           millis = media.RunMethodJO("getDuration", Null).RunMethod("toMillis", Null)
           Exit
       End If
   Next
   player.RunMethod("dispose", Null)
   Return millis
End Sub

Usage:
B4X:
Wait For(CreateMedia(...)) Complete (Millis As Double)
Log(Millis)

Relevant link: https://www.b4x.com/android/forum/threads/b4x-convert-milliseconds-to-string.89851/#content
 
Upvote 0

Damjan

Member
Thank you Erel!

So basically, I need to load the file into player and then get the info from the player. If I have 100 or more files this could be really slow.
 
Upvote 0
Top