2017-06-19 600 views
0

我在Excel工作表上添加了Windows Media Player ActiveX控件(WMPlayer2)和两个命令按钮,即cmd_PlayVideo和cmd_GetTimeCode。我想在Windows Media Player中播放视频,并在视频播放过程中单击cmd_GetTimeCode按钮时捕获视频的时间码。使用Windows Media Player的Excel VBA获取视频时间码时出现运行时错误

由于'currentPositionTimecode'属性在IWMPControls3接口中可用,所以我将WMPlayer2.controls的返回值转换为IWMPControls3接口。然而,行'MsgBox controls.currentPositionTimecode'抛出:

运行时错误430:“类不支持自动化或不支持预期的接口。

的IWMPControls3接口如audioLanguageCount,currentAudioLanguage,CURRENTITEM,controls.getAudioLanguageID,getLanguageName, 和getAudioLanguageDescription工作精细的其他性能。

如何获取视频的时间码?

这是我在2个按钮中的代码。

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") Then 
    Set 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 

回答

-1

我注意到一旦媒体开始播放,读取currentPositionTimecode参数只引发错误。也就是说,只有当媒体位置被重置为零(例如[00000] 00:00:00)时,它才会读取时间码位置而没有错误。我怀疑必须有一个标志来启用此功能(如CanScan?),或者媒体可能不支持SMPTE时间码。我仍在研究。