Im working on a media player for my work. It is suppose to be a song randomizer. I do have this mostly working. My issue is getting it to correctly switch songs when one ends. I just dont know why it is half working and half not. So my issue, after much debugging, which i have kept in my code i will post, i have found that when the song changes, the song does change, the index in the listbox goes up one and the 2nd song starts playing. I should note that i do have the code for playing the next song.....
commented out, but the song still plays. The issue then is that after it steps into my if statement, it changes the song index, resets the song in the media player to the new one, it goes out of the if statement because the media player state has changed, it goes back through the media player state change event like 3 times skipping over the if statement, then the next time through it goes back into the if statement where it resets the variable "song", then it moves onto my msgbox for debugging purposes and that tells me the song playstate is a 9, which means its transitioning. When i close the msgbox, the music stops. There is no where in the media state change event that tells it to stop, the only place that tells it to stop is my custom stop button i added on there. Another confusing thing, i use this same exact code in my custom next song button (actually a picture) and it works fine. So in all what i wanted is that the song ends, the listbox index goes up one to highlight a new song and then that song plays. It does do that, but then it stops. So after my long winded message, here is my code where it gets messed up:
Private Sub WMPwindow_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles WMPwindow.PlayStateChange If WMPwindow.playState = WMPPlayState.wmppsMediaEnded Then SongsListBox.SelectedIndex = SongsListBox.SelectedIndex + 1 song = "C:\Users\SamLemx\Desktop\Music\" & SongsListBox.SelectedItem.ToString WMPwindow.URL = song MsgBox(WMPwindow.playState) 'WMPwindow.Ctlcontrols.play() If WMPwindow.playState = WMPPlayState.wmppsPlaying Then Exit Sub End If End If End Sub
Im hoping this is enough information for people to be able to help. Thanks everyone.