0

I am writing a simple windows media player program with Visual Studio C# windows form. In the form I add a wmp component and a listbox. The listbox shows a list of songs. When user double clicks on a song in the listbox, the wmp plays the song without any problem. But when a song ends, the listbox selected item moves to the next song and the listbox double click function is called as well, but the wmp doesn't play the next song. How to fix the problem?

private void ListBoxDblClick(object sender, EventArgs e)
{
    Player.URL = ListBoxDblClick.SelectedItem.ToString();
    Player.Ctlcontrols.play();
}

private void Player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
    if (e.newState == 8) 
    {
        if (ListBoxDblClick.SelectedIndex < ListBoxDblClick.Items.Count - 1)
        {
            ListBoxDblClick.SelectedIndex = ListBoxDblClick.SelectedIndex + 1;
        }
        else
            if (ListBoxDblClick.SelectedIndex == ListBoxDblClick.Items.Count - 1)
            {
                ListBoxDblClick.SelectedIndex = 0;
            }
        ListBoxDblClick(sender, new EventArgs());
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
peter
  • 1,009
  • 3
  • 15
  • 23

1 Answers1

0

I think in the Player_PlayStateChange event, if the newstate == 8, you can not play a new song. What I do to solve the problem is that I add a timer, let the time ontick to play the next song.

Thanks.

peter
  • 1,009
  • 3
  • 15
  • 23