停止在电影XNA结束时播放视频

问题描述 投票:0回答:1

我在XNA播放.wmv电影。我玩它没有问题,但我似乎无法检测电影是否到达终点并停止播放电影。

我是这样做的:

Video video;
VideoPlayer player;

在更新方法上:

//Playing the movie
        #region
        if (playIntroMovie == true)
        {
            player.Play(video);
            player.Volume = 1;
            if (player.State == MediaState.Stopped)
            {
                player.Stop();
                videoTexture = null;
                playIntroMovie = false;
            }
        }
        #endregion

关于绘制方法:

if (player.State != MediaState.Stopped)
            videoTexture = player.GetTexture();
        if (videoTexture != null)
        {
            spriteBatch.Draw(videoTexture, fullScreenRec, Color.White);
        }

我知道如果moview已经结束,它的状态将返回MediaState.Stopped所以我试图阻止它并将其纹理设置为null。但电影又循环播放了。我包括了player.isLooped = false;但电影仍在循环中。什么导致问题的任何想法?

c# xna movie video-player
1个回答
1
投票

我认为这是因为在你的Update()循环中,你不断地调用player.Play()(playIntroMovie将一直为真,直到MediaState第一次命中Stopped)。

处理Update()循环逻辑的更好方法是这样的:

if (playIntroMovie == true)
{
    player.Play(video);
    playIntroMovie = false;
    player.Volume = 1;
}

if (player.State == MediaState.Stopped)
{
   player.Stop();
   videoTexture = null;
}
© www.soinside.com 2019 - 2024. All rights reserved.