I need to get the duration of a video file. I’m loading it in a MoviePlayer, playing it, grabbing the duration, then unloading it. Consider the following:
Movieplayer1.Movie = f.OpenAsMovie Movieplayer1.Volume = 0 Movieplayer1.Play Textfield1.text = MoviePlayer1.Duration.ToText Movieplayer1.stop Movieplayer1.close
This works fine on Windows. But on Mac, Textfield1 ends up getting NaN.
I’ve determined the problem is that the MoviePlayer doesn’t have enough time to start playing the movie before I query the Duration. If I wait anywhere from .5 to 3 seconds (depending on the file and where it is), I can poll .Duration and everything works.
But because the load time is variable and the .Play command seems to be non-blocking (next command executes immediately), I need to find out WHEN the MoviePlayer starts playing. Unfortunately, per the docs, I don’t see a way to query the status of the MoviePlayer (find out if it’s playing/paused/stopped/etc), unless I’m missing something.
The MoviePlayer.Play event also fires too early to query .Duration.
I could test the .Position value, but the precision of that value is in full seconds, which will introduce a 1s slow down in each loop of my application. Unacceptable when testing the lengths of hundreds or thousands of files.
Has anyone encountered this before and/or come up with a crafty workaround?