Reputation: 1541
I am working on vb.net application of video player using AxWindowsMediaPlayer
I have successfully created Playlist of bunch video files and it plays perfect.
I have more than 2 videos in the playlist.
I want to display message box which that file name when next video file get played from playlist.
Which event should I use ? and how to display which file is playing currently ?
I have used below code for creating playlist.
Private Sub PlayVideos()
Try
AxWindowsMediaPlayer1.uiMode = "full"
Dim Playlist As IWMPPlaylist = AxWindowsMediaPlayer1.playlistCollection.newPlaylist("Playlist1")
Dim VideoFile1 As WMPLib.IWMPMedia3 = AxWindowsMediaPlayer1.newMedia(Path1.Trim)
Playlist.appendItem(VideoFile1)
Dim VideoFile2 As WMPLib.IWMPMedia3 = AxWindowsMediaPlayer1.newMedia(Path2.Trim)
Playlist.appendItem(VideoFile2)
AxWindowsMediaPlayer1.currentPlaylist = Playlist
Catch ex As Exception
End Try
End Sub
Upvotes: 1
Views: 2533
Reputation: 1117
playstate change help for check if action change to media player add this to form1
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If (AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPlaying) Then
TextBox2.Text = "Opening..."
End If
With AxWindowsMediaPlayer1
Static Dim lasttrack As String = ""
Try
If .playState = WMPLib.WMPPlayState.wmppsPlaying And .currentMedia.name <> lasttrack Then
TextBox1.Text = (.currentMedia.name)
lasttrack = .currentMedia.name
End If
Catch
End Try
End With
Upvotes: 0
Reputation: 4439
this code should do it .. add it to the PlayStateChange event. The reason I have an empty try..catch statement in there is because while the media player is changing items, the playstatechange event fires several times, but until the next track is loaded, the currentmedia.name property is null and returns System.NullReferenceException. Eventually the currentMedia.name property is set to the new item and everything is happy. There may be a better way to do this, but it works for me.
With AxWindowsMediaPlayer1
Static Dim lasttrack As String = ""
Try
If .playState = WMPLib.WMPPlayState.wmppsPlaying And .currentMedia.name <> lasttrack Then
MessageBox.Show("Current playing track is " & .currentMedia.name)
lasttrack = .currentMedia.name
End If
Catch
End Try
End With
Upvotes: 2
Reputation: 27871
Handle the CurrentItemChange event.
Add the following code after setting the currentPlaylist
property:
AddHandler AxWindowsMediaPlayer1.CurrentItemChange,
Sub(s As Object, cic As AxWMPLib._WMPOCXEvents_CurrentItemChangeEvent)
Dim new_item As IWMPMedia = cic.pdispMedia
MsgBox(new_item.sourceURL)
End Sub
Upvotes: 0