3

Title says it all - I'm in VB.NET and using Windows Media Player as a base for a music player I'm making. I've got the following code to detect if a currently playing .mp3 file has ended:

            'Checks to see if the player is still playing music
            While WMPLib.WMPPlayState.wmppsPlaying
                    If WMPLib.WMPPlayState.wmppsMediaEnded Then
                    MessageBox.Show("Playing next song")
                    End If
            End While

The while check can successfully see that a music file is being played, however the IF statement doesn't detected when a music file has ended, it actually returns true whilst the media is currently playing. How can I get it to detect when a music file has finished playing?

Joshua
  • 40,822
  • 8
  • 72
  • 132
Novastorm
  • 1,439
  • 3
  • 26
  • 40

1 Answers1

2

You can use the CurrentItemChange() and PlayStateChange() events to see what is happening in the player:

Private Sub AxWindowsMediaPlayer1_CurrentItemChange(sender As Object, e As AxWMPLib._WMPOCXEvents_CurrentItemChangeEvent) Handles AxWindowsMediaPlayer1.CurrentItemChange
    Debug.Print("CurrentItemChange: " & Me.AxWindowsMediaPlayer1.currentMedia.name)
End Sub

Private Sub AxWindowsMediaPlayer1_PlayStateChange(sender As Object, e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
    Select Case e.newState
        Case 1 ' Stopped
            Debug.Print("Stopped")

        Case 2    ' Paused
            Debug.Print("Paused")

        Case 3 ' Playing
            Debug.Print("Playing")

        Case 4 ' ScanForward
            Debug.Print("ScanForward")

        Case 5 ' ScanReverse
            Debug.Print("ScanReverse")

        Case 6 ' Buffering
            Debug.Print("Buffering")

        Case 7 ' Waiting
            Debug.Print("Waiting")

        Case 8 ' MediaEnded
            Debug.Print("MediaEnded")

        Case 9 ' Transitioning
            Debug.Print("Transitioning")

        Case 10 ' Ready
            Debug.Print("Ready")

        Case 11 ' Reconnecting
            Debug.Print("Reconnecting")

        Case 12 ' Last
            Debug.Print("Last")

        Case Else
            Debug.Print("Undefined/Unknown: " & e.newState)

    End Select
End Sub
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40