Click here to Skip to main content
15,849,130 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
_BadFileCount = 0
For Each foundFile As String In My.Computer.FileSystem.GetFiles(aStrSrc, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, "*.MP4")

PlayListFile = wmp.mediaCollection.add(foundFile)

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
Exit For
End If
Catch ex As Exception
_BadFileCount += 1
End Try

I would be grateful for any help! Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900