I have to use the noted combination of tools, so suggestions that amount to "don't do that" are not helpful (-:
I can find no reliable way to determine the framerate of a video loaded into a WMP control. Is there some known way to get this value? It's such a basic piece of info that I can't believe I'm not missing something.
In theory I can instance IWMPMedia3
and set that to [player].currentmedia
then ask for .GetAttributeByType("framerate", "", 0)
, but apparently there is some state that the player/media must be in for that to work, and I can't determine when that state exists.
In the IDE, when I try to get the attribute it always fails with Invalid procedure call or argument
. I open the debug window and test whether the correct objects are instantiated -- they are. Then I can continue and I have the correct framerate. Clearly that won't work in production. (-:
It's not just waiting that does the trick -- I must actually debug test for Nothing on the objects to get it to proceed.
It appears the framerate item does not get initialized immediately after you set a source video to the control. I tried to wait and call DoEvents and at first found no reliable way to get it working. Displaying a message box and waiting 30 seconds sometimes did it, but not always.
I then decided to examine the attribute by code, and to my surprise, simply checking using getAttributeCountByType() seems to initialize the item without waiting a single millisecond.
In the following code, if the checkbox is enabled, which calls getAttributeCountByType(), the function always succeeds. I tried with AVI, MPEG and MP4 files and it worked on Windows 7. If the checkbox is not checked, it always fails with all types of video files:
WindowsMediaPlayer1.URL = Text1.Text
Dim media As IWMPMedia3
Set media = WindowsMediaPlayer1.currentMedia
If Check1.Value = vbChecked Then
Label1.Caption = "media.getAttributeCountByType " & media.getAttributeCountByType("framerate", "")
End If
MsgBox "Frame Rate = " & media.getItemInfoByType("framerate", "", 0)