2

I am trying to get the Duration of the video that i have loaded into my Windows Media Player but it seems to be returning back '0.0'

I need the duration value before the video starts playing as the video length determines the width of a slide.

This is how i am trying to do it at the moment:

timeElapsed = AxWindowsMediaPlayer_OnDemand.currentMedia.duration - marker.SyncTime

I have also tried this which returns an empty string:

Dim asas As String = AxWindowsMediaPlayer_OnDemand.currentMedia.getItemInfo("Duration")

Does anyone have any idea of how to get the length of the video loaded in?

4

1 回答 1

1

添加对 Windows Media Player 的引用

在函数中使用以下 2 行来调用它

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
于 2018-08-23T18:19:22.740 回答