我正在尝试获取已加载到我的Windows Media Player中的视频的持续时间,但它似乎又返回'0.0'
我需要在视频开始播放之前的持续时间值,因为视频长度决定了幻灯片的宽度。
这就是我现在尝试这样做的方式:
timeElapsed = AxWindowsMediaPlayer_OnDemand.currentMedia.duration - marker.SyncTime
我也试过这个,它返回一个空字符串:
Dim asas As String = AxWindowsMediaPlayer_OnDemand.currentMedia.getItemInfo("Duration")
有没有人知道如何获取加载的视频的长度?
答案 0 :(得分:0)
添加对Windows Media Player的引用
在函数中使用以下两行进行调用
Dim VidSecs As Integer = Math.Round(GetMediaDuration(YourFilePath))'Get total seconds
Dim Vidhhmmss As String = TimeSpan.FromSeconds(Math.Round(GetMediaDuration(YourFilePath))).ToString ' Format hh:mm:ss
Public Function GetMediaDuration(ByVal MediaFile As String)
Try
Dim w As New WMPLib.WindowsMediaPlayer
Dim m As WMPLib.IWMPMedia = w.newMedia(MediaFile)
w.close()
Return m.duration
Catch ex As Exception
Return 0
End Try
End Function