문제

I need to player to automatically go to the next song in the listBox and play it, but it won't play. I have it where it goes to the next song, but when it changes it doesn't start playing. Here is a snippet of the code:

if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{
    if (listBox1.SelectedIndex != listBox1.Items.Count - 1)
    {
        listBox1.SelectedIndex = listBox1.SelectedIndex + 1;
    }
}

I use this same method for the "Next" and "Previous" buttons and it works perfectly.

I have also tried this:

if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{
    listBox1.SelectedIndex = listBox1.SelectedIndex + 1;
    axWindowsMediaPlayer1.Ctlcontrols.play();
}

It goes to the next song, but as stated before, just doesn't play.

How can I get it to play?

도움이 되었습니까?

해결책

You can use PlayStateChange Event Handler :

 private void WindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
if (e.newState == 1)
        {
            if (listBox1.SelectedIndex != listBox1.Items.Count - 1)
            {
                BeginInvoke(new Action(() => {
                    listBox1.SelectedIndex = listBox1.SelectedIndex + 1
                }));
            }
        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top