Search code examples
vb.netmedia-playersubroutinewindows-media-player

Windows Media Player PlayStateChange


I am using Visual Basic.net and the Windows Media Player control. Is it possible to determine the Object when the PlayStateChange event occurs.

Here is the sub:

PlayStateChange(NewState As Integer)

There is no Sender Object in the sub. Is it possible to get the Object by overriding the sub or by another way?

Thanks in advance

UPDATE

Here is the code I used to use the control:

    Public WithEvents MediaPlayerObject As WindowsMediaPlayer = New WindowsMediaPlayer

Solution

  • I just added a Windows Media Player Control and subscribed to the PlayStateChange Event using the Form's Property Editor, the generated EventHandler has a signature of:

    Private Sub AxWindowsMediaPlayer1_PlayStateChange(sender As System.Object, e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
    
    End Sub
    

    which is what you were expecting, how did you add your Control and the EventHandler?


    It looks like you are importing the WindowsMediaPlayer Library directly. Try right clicking your toolbox and selecting Choose Items Go to the COM tab and select WindowsMediaPlayer. You can then drop it on your Form. This will also create the proper Wrapper for the ActiveX control.