Consulting

Results 1 to 5 of 5

Thread: Excel VBA with Windows Media Player: Runtime error while getting video timecode

  1. #1
    VBAX Newbie
    Joined
    Jun 2017
    Posts
    3
    Location

    Excel VBA with Windows Media Player: Runtime error while getting video timecode

    I've added a Windows Media Player ActiveX control (WMPlayer2) and two command buttons, viz, cmd_PlayVideo and cmd_GetTimeCode on an Excel sheet. I would like to play a video in Windows Media Player and capture the timecode of the video as and when I click the cmd_GetTimeCode button while the video is being played.

    Since the 'currentPositionTimecode' property is available in IWMPControls3 interface, I've cast the return value from WMPlayer2.controls to the IWMPControls3 interface. However, the line 'MsgBox controls.currentPositionTimecode' throws: run-time error 430: "Class does not support Automation or does not support expected interface." The other properties of the IWMPControls3 interface such as audioLanguageCount, currentAudioLanguage, currentItem, controls.getAudioLanguageID, getLanguageName, and getAudioLanguageDescription work fine.

    How can I get the timecode of the video?
    Here is my code in 2 buttons.
    -------------------------------------------------------------------------

    Private Sub cmd_PlayVideo_Click()
    
    MsgBox Application.Sheets("Sheet1").Range("B2")
    WMPlayer2.URL = Application.Sheets("Sheet1").Range("B2")
    
    End Sub
    -------------------------------------------------------------------------

    Private Sub cmd_GetTimeCode_Click()
    
    Dim controls As WMPLib.IWMPControls3
    Dim Media As WMPLib.IWMPMedia
    Set controls = WMPlayer2.controls
    
    MsgBox controls.audioLanguageCount
    MsgBox controls.currentAudioLanguage
    If controls.isAvailable("currentItem") ThenSet Media = controls.currentItem
    MsgBox Media.durationString
    MsgBox Media.Name
    MsgBox Media.SourceUrl
    End If
    
    MsgBox controls.getAudioLanguageID(1)
    MsgBox controls.getLanguageName(1)
    MsgBox controls.getAudioLanguageDescription(1)
    MsgBox controls.currentPositionTimecode
    
    End Sub
    Last edited by SamT; 06-19-2017 at 06:09 PM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    First, I would never use "controls" as a variable name because it is a Key Word in VBA. I suspect that "Media" is also a Key Word.. I suggest "Ctrls" and "MdiaPlyr."

    Try using currentPosition, a Double, or currentPositionString, a String, instead of currentPositionTimeCode, also a String. Just to see what happens.

    THere is a slim chance that you must use IWMPControls or IWMPControls2.

    Sometimes you have to cast many spells to see which one makes the pot boil.
    Last edited by SamT; 06-19-2017 at 06:13 PM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Newbie
    Joined
    Jun 2017
    Posts
    3
    Location
    Thanks SamT for your response. I tried both the 'currentPosition' and 'currentPositionString' properties and they seem to work fine.
    I don't know how to cast the 'currentPositionTimeCode' into IWMPControls or IWMPControls2 interfaces. Also, the currentPositionTimeCode property is available only for IWMPControls3 interface, which is a member of WMPLib. The IWMPControls or IWMPControls2 interfaces do not have the currentPositionTimeCode property. Hence I didn't think of casting into IWMPControls or IWMPControls2. I would appreciate if you please show me how to cast into IWMPControls or IWMPControls2 interfaces in VBA.

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    please show me how to cast into IWMPControls or IWMPControls2 interfaces in VBA.
    They must be available in Tools >> References. then
    Dim Ctrls As WMPLib.IWMPControls
    and
    Dim Ctrls As WMPLib.IWMPControls2
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    VBAX Newbie
    Joined
    Jun 2017
    Posts
    3
    Location
    Quote Originally Posted by SamT View Post
    They must be available in Tools >> References. then
    Dim Ctrls As WMPLib.IWMPControls
    and
    Dim Ctrls As WMPLib.IWMPControls2
    I tried both IWMPControls and IWMPControls2 and I still get the same run-time error 430.
    Any other suggestions are welcome.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •