[RESOLVED] Play next song in Windows Media Player 11.0
Hi,
Way back in 2002 I used this code to play the next song in the song list in Windows Media Player under Windows XP. However, that code no longer seems to work under Windows Vista or Windows 7. Does anyone have a solution to this problem?
Edit:
The "EndofStream" does not seem to work in Vista or Windows 7 I will check this again after I have installed the latest Windows updates.
vb Code:
Private Sub MediaPlayer1_EndOfStream(ByVal Result As Long)
'If MediaPlayer1.Controls.currentPositionString >= MediaPlayer1.currentMedia.durationString Then
MsgBox ("This is working!")
'End If
End Sub
Thanks,
Nightwalker
Re: Play next song in Windows Media Player
I solved the problem by storing the item position of frmSetup.Lstsongs in a variable:
vb Code:
Private Sub Form_Load()
'Integer index of the song to be played
s = 0
End Sub
Sending the variable to the function:
vb Code:
Private Sub mnuPlay_Click()
'If cancel then close the program
'Else choose and play a song
Music1.ShowOpen
frmSetup.Lstsongs.AddItem Music1.FileName
Repeat:
x = MsgBox("Do you want to add more songs?", vbYesNo)
If x = vbYes Then
Music1.ShowOpen
frmSetup.Songopt(1).Value = True
frmSetup.Lstsongs.AddItem Music1.FileName
GoTo Repeat
ElseIf x = vbNo Then
play (s)
End If
End Sub
The "play" function:
vb Code:
Private Function play(s)
frmSetup.Lstsongs.Selected(s) = True
MediaPlayer1.URL = frmSetup.Lstsongs.Text
End Function
Finally checking inside a timer to check if the player had stopped, there was more than one song in the list and whether or not s was greater than the value of the number of songs in the listbox. If all those conditions were met then I would add 1 to the value of s and send the new value back to the play function.
vb Code:
Private Sub tmrDuration_Timer()
If MediaPlayer1.playState = wmppsStopped And frmSetup.Songopt(1).Value = True And Not s > frmSetup.Lstsongs.ListCount Then
'Play the next song in the list
s = s + 1
play (s)
End If
End Sub