3

标题说明了一切 - 我在 VB.NET 中并使用 Windows Media Player 作为我正在制作的音乐播放器的基础。我有以下代码来检测当前播放的 .mp3 文件是否已结束:

            '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

while 检查可以成功地看到正在播放音乐文件,但是 IF 语句没有检测到音乐文件何时结束,它实际上在媒体当前播放时返回 true。如何让它检测音乐文件何时播放完毕?

4

1 回答 1

2

您可以使用 CurrentItemChange() 和 PlayStateChange() 事件来查看播放器中发生了什么:

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
于 2015-01-31T17:02:40.577 回答