I'm using a windows media control (AxWMPLib.AxWindowsMediaPlayer) in a Winforms app to play an mp4 video. I want to be able to start the video at a particular position and then stop playing after a certain number of seconds.
My problem is that when I try to set the current position, it either sets the current position to zero (before it starts to play or when it's paused) or a small number such as 6 (if it's already playing).
This is how I'm trying to change the current position:
m_windowsMediaPlayer.Ctlcontrols.currentPosition = value;
This question Embedded Windows Media Player Set Position is slow suggests that the problem could be caused by a low number of key frames, but it doesn't matter whether I try to set it to 30 seconds or 1200 seconds. It still starts playing at 6 seconds again.
This question Windows Media Player control - get/set video position? shows that setting currentPosition works for some people.
Here's the relevant code:
m_windowsMediaPlayer.URL = GetVideoFileFullPath();
RestartVideo();
private void RestartVideo()
{
m_windowsMediaPlayer.Ctlcontrols.currentPosition = StartTime;
StopTimer();
StartTimer();
m_windowsMediaPlayer.Ctlcontrols.play();
}
I also tried adding an OpenStateChanged event since I thought maybe everything was delayed, so I should set it only after the file was truly opened. But that didn't help either.
private void m_windowsMediaPlayer_OpenStateChange(object sender, AxWMPLib._WMPOCXEvents_OpenStateChangeEvent e)
{
if (m_windowsMediaPlayer.playState == WMPLib.WMPPlayState.wmppsPlaying)
{
if (m_start)
{
m_windowsMediaPlayer.Ctlcontrols.pause();
m_start=false;
RestartVideo();
}
}
}
The mp4 file that I'm displaying is still being appended to by another app. But the problem exists with static mp4 files too. If another video format would work better, I should be able to change the other app to use that video format. I looked at using vlcDotNetForms, but since I want to be able to distribute this app with as few external dependencies as possible, I am hoping to solve this by using something that ships with windows.
One other point: I need to support Windows Vista machines on up, and I can't count on them having .NET 3.5 or newer. Currently I'm targeting .NET 2, but I could target .NET 3 if necessary. I'm seeing these problem on Windows 8.1.