我尝试在同一个axmediaplayer中播放2个视频。我的理论是这样的:主要电影将播放,直到计时器事件发生。然后播放新电影,最后一个电影位置将保存,完成第二部电影后,最后一部电影将从上一部电影位置继续播放。
但在完成第二部电影后,我的axmediplayer不会工作,不会继续第一部电影......
我在网上搜索,有人说因为从事件处理程序调用URL而发生这种情况。但我不知道如何解决它以及如何将其设置为处理程序...
private void timerTeserInterval_Tick(object sender, EventArgs e)
{
if (this.MoviePlayerCanPlayTeaser && playerMode != PlayerMode.TeaserMode && axWindowsMediaPlayer.playState == WMPLib.WMPPlayState.wmppsPlaying)
{
MoviePlayerCurrentPossition = Convert.ToInt32(axWindowsMediaPlayer.Ctlcontrols.currentPosition);
LastMovieName = MoviePathFile;
axWindowsMediaPlayer.Ctlcontrols.pause();
}
}
private void PlayMovie()
{
if (MovieNameList == null || MovieNameList.Count == 0)
return;
if (playerMode == PlayerMode.MovieMode && MoviePlayerCurrentPossition == 0)
{
if (MovieNameListIndex < MovieNameList.Count)
{
MoviePathFile = MovieFolder + "\\" + MovieNameList[MovieNameListIndex];
MovieNameListIndex++;
}
else
{
MovieNameListIndex = 0;
MoviePathFile = MovieFolder + "\\" + MovieNameList[MovieNameListIndex];
MovieNameListIndex++;
}
try
{
axWindowsMediaPlayer.URL = MoviePathFile;
if (axWindowsMediaPlayer.URL != "" && axWindowsMediaPlayer.URL != null)
{
axWindowsMediaPlayer.Ctlcontrols.play();
playerMode = PlayerMode.MovieMode;
}
}
catch { }
}
else if (MoviePlayerCurrentPossition != 0)
{
try
{
axWindowsMediaPlayer.URL = LastMovieName;
axWindowsMediaPlayer.Ctlcontrols.currentPosition = MoviePlayerCurrentPossition;
if (axWindowsMediaPlayer.URL != "" && axWindowsMediaPlayer.URL != null)
{
axWindowsMediaPlayer.Ctlcontrols.play();
playerMode = PlayerMode.MovieMode;
}
MoviePlayerCurrentPossition = 0;
}
catch { }
}
}
private void PlayTeaser()
{
if (this.MoviePlayerCanPlayTeaser)
{
if (TeaserNameList == null || TeaserNameList.Count == 0)
return;
if (TeaserNameListIndex < TeaserNameList.Count)
{
TeaserPathFile = TeaserFolder + "\\" + TeaserNameList[TeaserNameListIndex];
TeaserNameListIndex++;
}
else
{
TeaserNameListIndex = 0;
TeaserPathFile = TeaserFolder + "\\" + TeaserNameList[TeaserNameListIndex];
TeaserNameListIndex++;
}
try
{
axWindowsMediaPlayer.URL = TeaserPathFile;
if (axWindowsMediaPlayer.URL != "" && axWindowsMediaPlayer.URL != null)
{
playerMode = PlayerMode.TeaserMode;
axWindowsMediaPlayer.Ctlcontrols.play();
}
}
catch { }
}
}
private void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (axWindowsMediaPlayer.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{
playerMode = PlayerMode.MovieMode;
PlayMovie();
}
else if (axWindowsMediaPlayer.playState == WMPLib.WMPPlayState.wmppsPaused)
{
playerMode = MoviePlayer.PlayerMode.TeaserMode;
PlayTeaser();
}
}