Search code examples
c#winformsaxwindowsmediaplayer

Prevent axWindowsMediaPlayer stop after media end


I am creating a c# winform application to play video, what i want is to pause the player and prevent that to stop after media ending:

private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
    {
        if (e.newState == 8)//media ended
        {
            //To pause and prevent stop.
        }
    }

I tested some things:

if (e.newState == 8)
        {
            axWindowsMediaPlayer1.Ctlcontrols.pause();
        }

but after this player automatically goes to stop. after this test:

if (e.newState == 8)
        {
            axWindowsMediaPlayer1.Ctlcontrols.pause();
            Thread.CurrentThread.Join(5000);
        }

The player pauses and wait for 5 seconds then stop! Do you have a solution for this? Thanks.


Solution

  • Try:

        private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {
            if (e.newState == 1)
            {
                axWindowsMediaPlayer1.Ctlcontrols.currentPosition = axWindowsMediaPlayer1.currentMedia.duration - .001;
                axWindowsMediaPlayer1.Ctlcontrols.play();
                axWindowsMediaPlayer1.Ctlcontrols.pause();
            }
        }