C# Media Player PlayStateChange not firing

431 Views Asked by At

Trying to get a WMPLib to go to the next track when the current one ends. My code is below, but it never fires. I've tried with WMPLib.WMPPlayState.wmppsStopped as well as WMPLib.WMPPlayState.wmppsMediaEnded and it never fires. Anyone see what I'm doing wrong? The media player is afile.

Thanks in advance.

private void mediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
        MessageBox.Show("Playstate Has Fired");
        if (mediaPlayer.playState == WMPLib.WMPPlayState.wmppsStopped)  // check if file has ended.
        {
            try
            {
                listFiles.SelectedIndex++;
            }
            catch (Exception)
            {
                if (chkLoop.Checked)
                {
                    listFiles.SelectedIndex = 0;
                }
                else
                {
                    afile.controls.stop();
                }
            }

        }
    }
1

There are 1 best solutions below

3
Sintrigue Sintrigue On

Thank you, I got this figured out by using a timer_tick event, and adding this to it:

if (afile.playState == WMPLib.WMPPlayState.wmppsStopped)
        {
            listFiles.SelectedIndex++;
        }

Works great. Thanks again.