I'm trying to reliably get the duration of all MP4 media items I've loaded into a playlist, and found the following in MSDN:
'If <duration> property is used with a media item other than the one specified in
'AxWindowsMediaPlayer.currentMedia, it may not contain a valid value.
'To retrieve the duration for files that are not in the user's library,
'you must wait for Windows Media Player to open the file; that is, the current
'OpenState must equal MediaOpen. You can verify this by handling the '
'AxWindowsMediaPlayer._WMPOCXEvents_OpenStateChange event or by periodically
'checking the value of AxWindowsMediaPlayer.openState.
So, I tried to run through all the files in the playlist and momentarily 'open' them so I can read this property, but my question is - what is necessary to actually have WMP 'open' the media item? Here's my code - 'wmp' is my instance of axWindowsMediaPlayer Dim'd elsewhere.
Dim PlayListFile As WMPLib.IWMPMedia
Me.wmp.currentPlaylist.clear() 'alo Stops WMP playback
lbPlayList.Items.Clear()
_BadFileCount = 0
For Each foundFile As String In My.Computer.FileSystem.GetFiles(aStrSrc, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.MP4")
Try
PlayListFile = wmp.mediaCollection.add(foundFile)
Me.wmp.currentPlaylist.appendItem(PlayListFile)
Me.wmp.currentMedia = PlayListFile 'Apparently, this does not open the file.
For i As Integer = 1 To 100000
If wmp.openState = WMPLib.WMPOpenState.wmposMediaOpen Then
lbPlayList.Items.Add(CStr(Me.wmp.currentMedia.duration))
Exit For
End If
Next
Catch ex As Exception
_BadFileCount += 1
End Try
Next
I would be grateful for any help! Thanks!