Function call only works when MessageBox.Show() is included?

前端 未结 1 485
遥遥无期
遥遥无期 2020-12-02 02:45

In my current project I have a self-made audioplayer which is operated trough my musictimer() function. Below is a sub which orders the audioplayer to go to the next song wh

相关标签:
1条回答
  • 2020-12-02 03:07

    The PlayStateChanged event is quite notorious. It was really meant to just update a UI element that shows the state. Doing anything with the player in that event is very troublesome. A call to MessagBox can have an affect because it pumps a message loop, always a big deal for ActiveX controls.

    The best way to stay out of trouble is by delaying your code, making it run after the event was fired and the player is back into a quiescent state. Elegantly done by using the Control.BeginInvoke() method. Like this:

    Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
        If e.newState = WMPLib.WMPPlayState.wmppsStopped Then
            Me.BeginInvoke(New Action(AddressOf NextSong))
        End If
    End Sub
    
    Private Sub NextSong()
        musictimer("next")
    End Sub
    
    0 讨论(0)
提交回复
热议问题