Question

I am using the AxWindowsMediaPlayer control in a Winforms C# application and I would like to set the player to pause on the last frame when the video is finished playing. I already handle the fact that the video is finished to display another control with a different content over the player, but I want to avoid the blank frame that shows up in between.

Is it possible to configure the player to pause on the last frame? Or is there an event I could handle to set the video to pause on the last last frame or the last few milliseconds?

PS. The PositionChange event seems to be raised only when the position is set by the user or in code so I can't use it. The MarkerHit event seemed promising, but I can't find any way to set a marker in the video so that didn't work either.

Was it helpful?

Solution

It's not quite as simple as Nadhmi (@user5330265) makes out. The video may finish playing and reset to a blank frame between the timer ticks, in which case the pause is never executed.

I've found the following works, at the cost of missing the last iInterval msec of the video. tmrVideo timer interval is set to 1 msec. On my system it seems to run about every 15 msec, but diagnostics slow it down. It doesn't seem to add to the overall CPU load. I use a value of 250 for iInterval - currentPosition never seems to reach duration. Smaller values mean less lost video, but a greater chance of the blank frame appearing.

currentPosition is zero while the video is loading, which is why the test needs to be added to the condition.

tmrVideo need to be enabled after every axWindowsMediaPlayer1.Ctlcontrols.play() command.

private void tmrVideo_Tick(object sender, EventArgs e)
    {
        if ((axWindowsMediaPlayer1.currentMedia.duration - axWindowsMediaPlayer1.Ctlcontrols.currentPosition)*1000 < 
            iInterval) && 
            axWindowsMediaPlayer1.Ctlcontrols.currentPosition!= 0)
        {
            axWindowsMediaPlayer1.Ctlcontrols.pause();
            tmrVideo.Enabled = false;
        }                           
    }

OTHER TIPS

Hi

Its as simple as this.

First, you need to add a timer. Now handle the Timer1_Tick event:

if (AxWindowsMediaPlayer1.Ctlcontrols.currentPosition == AxWindowsMediaPlayer1.currentMedia.duration) {
    AxWindowsMediaPlayer1.Ctlcontrols.pause();
}

That's it

PS: make sure to start the timer.

Nadhmi.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top