Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm making an mp3 player using the AxWindowsMediaPlayer but I haven't figured out how to make one song play followed by the next without using wmp.playlist. And when I tried using the playlist I ran into a problem. I have a listbox with the files on the playlist and I want to be able to double click on an item and play it. If I change the player.currentMedia on the listbox1.doubleClick event, the player forgets about the previous playlist and just plays the one file until it finishes. I tried comparing the playlist.item index to the listbox.selectedindex and then move to the next song (or previous) as many times as needed to get to the right song selected on the listbox. I came up with this code but it's not working properly, it just advances to the next item on the playlist whenever i double click any item on the listbox.
VB
If Player.playState = WMPPlayState.wmppsPlaying Then 'And TrackBar1.Value = 1 Then
            For i = 0 To Player.currentPlaylist.count - 1
                If Player.currentMedia.isIdentical(Player.currentPlaylist.Item(i)) Then
                    If i < ListBox1.SelectedIndex Then
                        MsgBox(i.ToString + vbCrLf + ListBox1.SelectedIndex.ToString)
                        While i < ListBox1.SelectedIndex
                            Player.Ctlcontrols.next()
                            i += 1
                        End While
                    End If
                    If i > ListBox1.SelectedIndex Then
                        While i > ListBox1.SelectedIndex
                            Player.Ctlcontrols.previous()
                            i -= 1
                        End While
                    End If
                    'Label3.Text = "Currently Playing Media Index: " & i.ToString
                    'MsgBox("Currently Playing Media Index: " & i.ToString)
                End If
            Next
        End If

If the playlist index is greater than the listbox.selectedindex (I selected a song that's before the one that's playing) it works just fine. It's when I try to select a song that's after the one that's playing that it won't work. Any ideas?
I've been searching the web trying to find examples but I just find simple code that plays one song. Nothing about loop playing or shuffle playing or anything.
If someone has a better idea of how I could do this it would be of great help to me!
Posted
Updated 30-Nov-16 21:39pm
v2

1 solution

Public Sub PlayNext()
Try
ColorSliderProgress.Value = 0
If Not ListBox2.SelectedIndex < 0 Then
If ListBox1.SelectedIndex > ListBox1.Items.Count - 1 Then
ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
AxWindowsMediaPlayer1.URL = ListBox1.SelectedItem
AxWindowsMediaPlayer1.Ctlcontrols.play()
End If
End If

Catch ex As Exception

End Try
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900