VideoView Issues

NJDude

Expert
Licensed User
Longtime User
It seems the VideoView is VERY buggy, I have read some postings about getting the wrong duration (possible corrupted meta data, etc)
B4X:
...

VidDuration = mVideoView.Duration

...

So, my question is, how do I get the "right" value?, does anyone have a solution?

Thanks.
 

blong

Active Member
Licensed User
Longtime User
Codec

I think the problem with media files is that formats such as AVI are just wrappers and depend on external codecs to decode... including runtime or duration of the file.

I know when I did this in VB that I used a 3rd party add-on that involved opening a media file and then using a property to get its runtime length. This took time and in my case where i had 500+ movies in a database I actually used to open files only once and then save movie info in a small text file in the movie directory.

If text file existed do not open file...

If no text file i.e. first time I have checked this move, open the file, get duration, close file and save information to the text file.

As you are already going through this OPEN process I conclude that VideoView may not be the main problem but rather the dependent codecs underneath.

My experience with VideoView is that is the Android device has good codec library then all works fine, including HD playback. BUT without good codecs then HD playback is not possible and probably DURATION is also buggy.

On a device I have i installed many media players ... none of them worked OK until I found one that also had a specific codec pack designed for the Android device processor .. ie ARM7 or ARM5 or whatever.

IMHO ..Find some new codecs and then retry VideoView ...

Please let me know how you fare in this ...
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I found the solution and it works consistently on all my devices and Android versions.

Instead of using the VideoView duration, use the MediaPlayer duration, let's say I have an MP4 named MyVideo, this is how I get the duration.
B4X:
Dim mp As MediaPlayer

mp.Load(File.DirDefaultExternal, "MyVideo.mp4")

seconds = Floor(mp.Duration / 1000 Mod 60)
minutes = Floor(mp.Duration / (1000 * 60) Mod 60)
hours = Floor(mp.Duration / (1000 * 60 * 60) Mod 24)

Duration = NumberFormat(hours, 2, 0) & ":" & NumberFormat(minutes, 2, 0) & ":" & NumberFormat(seconds, 2, 0)   

MsgBox("File Duration: " & Duration, "")
I have tried only using MP4 and it's perfect, I haven't tried other formats because in my case, I'm just working with MP4 files.
 
Upvote 0

blong

Active Member
Licensed User
Longtime User
Duration

NJDude

Just been playing with VideoView duration.

It does not seem to give a value UNTIL video is actually playing ...

so even if you issue the vv.LoadVideo(...)

you have to wait until after vv.play before can query the duration.

Could that have been your problem before ???

Media Player must somehow do it during the Load command
 
Upvote 0
Top