Android Question VideoView duration problem ?

bagazhou

Member
Licensed User
Longtime User
Hi

i use VideoView to play some video, i test some mp4 and avi, play is ok, but duration always is -1, how can i get the video duration ?


B4X:
Sub Globals
   Dim vv As VideoViewExt

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("frmMain")
   
   vv.Initialize("vv")
   vv.MediaControllerEnabled = False
   Activity.AddView(vv, 0dip, 0dip, 74%x, 100%y)


End Sub


Sub Activity_Resume
   If File.Exists(File.DirAssets,"5.mp4") = False Then
       Log("mp4 not found")
   Else
       File.Copy(File.DirAssets,"5.mp4",File.DirInternal,"5.mp4")
       Log("mp4 already copy")
   End If
   
   vv.LoadVideo(File.DirInternal,"5.mp4")
   vv.Play
   Log("vv.Duration:" & vv.Duration)
   
   
End Sub

LOG:
** Activity (frmmain) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (frmmain) Create, isFirst = true **
** Activity (frmmain) Resume **
mp4 already copy
vv.Duration:-1
 

bagazhou

Member
Licensed User
Longtime User
I found the solution , to get the video duration must be in prepared event ,because video is prepared ,start calculate video duration

B4X:
Sub vv_prepared
   Log("vv1.Duration:" & vv.Duration)
End Sub
 
Upvote 0
Top