axWindowsMediaPlayer:循环播放时出现黑屏 [英] axWindowsMediaPlayer: Black Screen on looping

查看:53
本文介绍了axWindowsMediaPlayer:循环播放时出现黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个具有 axWindowsMediaPlayer 控件的 Windows 窗体应用程序.我尚未在其上创建播放列表,但我已将 .mp4 文件存储在特定位置.我在 媒体结束 状态下将路径传递到我的下一个视频.玩家第一次收到正确的路径并开始游戏.但是对于第二个视频,尽管播放器正在接收正确的播放路径,但我只能看到黑屏.

I have created a Windows Form Application having axWindowsMediaPlayer control. I haven't created a playlist on it, but I have stored my .mp4 files at a particular location. I pass the path to my next video at Media Ended state. For the first time, the player receives the correct path and play. But for the second video, I can only see a black screen although the player is receiving the correct path to play.

这是我的媒体结束状态代码:

Here is my code for Media Ended State:

private void axWindowsMediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
  if(e.newState == 8)
    {
      //Getting jumpTo of selected page
      var selectedElementJumpToValue = MainContentAreaBl.GetSelectedElementValue(_currentId, "jumpTo");
      if (selectedElementJumpToValue != null)
      {
        _currentId = selectedElementJumpToValue;
        if (_currentId != "menu")
        {
          pagination.Text = MainContentAreaBl.GetPaginationText(_currentId);                        
          LaunchPlayer(selectedElementJumpToValue);
        }
        else
        {
          this.Hide();
          this.SendToBack();
          menu.BringToFront();
        }
    }
  }
}

private void LaunchPlayer(string id)
{
  string selectedElementPageTypeValue = MainContentAreaBl.GetSelectedElementPageTypeValue(id);
  var playerFile = Path.Combine(Common.ContentFolderPath, MainContentAreaBl.GetSelectedElementDataPathValue(id));                
  if (selectedElementPageTypeValue == "video")
  {
    InitialiseMediaPlayer();
    axShockwaveFlash.Stop();
    axShockwaveFlash.Visible = false;              
    if (File.Exists(playerFile))               
    {
      axWindowsMediaPlayer.URL = playerFile;
    }               
  }
  else if (selectedElementPageTypeValue == "flash")
  {
    InitialiseShockwaveFlash();
    axWindowsMediaPlayer.close();
    axWindowsMediaPlayer.Visible = false;
    if (File.Exists(playerFile))
    {
      axShockwaveFlash.Movie = playerFile;
      axShockwaveFlash.Play();
    }                
  }
}

private void InitialiseMediaPlayer()
{
  axWindowsMediaPlayer.Visible = true;
  axWindowsMediaPlayer.enableContextMenu = false           
  axWindowsMediaPlayer.uiMode = "none";
  axWindowsMediaPlayer.Dock = DockStyle.Fill;
}

当我调试我的应用程序时,我看到媒体播放器在 e.newState == 10(就绪状态)之后获得了正确的路径.我做错了什么?

When I debugged my application, I saw Media Player getting the correct path after e.newState == 10 (Ready state). What am I doing wrong?

编辑 1: 我发现在我当前的视频进入媒体结束状态后,播放器停止播放.即使我写了 axWindowsMediaPlayer.ctlControls.play();,它也不会影响媒体播放器.这是 axWindowsMediaPlayer 中的错误吗?

Edit 1: I found out that after my current video enters into Media Ended state, the player is stopped from playing. Even if I write axWindowsMediaPlayer.ctlControls.play();, it doesn't affect the media player. Is this a bug from in axWindowsMediaPlayer?

推荐答案

我以前也遇到过这个问题.最可能的原因是您在播放状态仍在更改时发出命令 axWindowsMediaPlayer.ctlControls.play();(在 Media Ended 之后,它将更改为 <强>就绪状态).如果在播放状态改变时向播放器发送命令,它不会做任何事情.另一个可能的错误原因是有时媒体状态 9(转换)需要包含在 if(e.newState == 8) 中,这样您就有 if(e.newState ==8 | e.newState==9).我曾遇到过它在状态 8(媒体结束)上没有回升的情况,可能是因为它发生得非常快并跳转到过渡 - 不完全确定这个原因,但我有一个播放器没有移动到下一个视频由于这种情况发生在播放列表中.为了解决这个问题,我做了类似的事情:

I have encountered this issue before as well. The most likely cause is that you are giving the command axWindowsMediaPlayer.ctlControls.play(); while the play state is still changing ( after Media Ended, it will change to Ready state). If a command is sent to the player while the play state is changing, it won't do anything. Another possible cause of your error is that sometimes Media State 9 (transitioning) needs to be included with if(e.newState == 8) such that you have if(e.newState == 8 | e.newState==9). I have had cases where it doesn't pick up on State 8 (media ending), possibly because it happens really fast and jumps to transitioning - not completely sure of this cause but I had a player that wasn't moving to the next video in the playlist because of this happening. To solve this I did something like:

  if (e.newState == 8 | e.newState== 9 | e.newState== 10)
            {
                if (e.newState == 8)
                { //Insert your code here
            }

这会略有不同,具体取决于您要实现的目标.另一件需要注意的事情是使用 PlayStateChange 事件来设置视频 URL,这会由于 WMP 的重新输入问题而导致问题 - 请参阅其他帖子以进一步解释我的最后一条评论:这里有一个很好的另一个在这里.希望这会有所帮助!

This would vary slightly depending on what you are trying to achieve. Another thing to watch out for is using the PlayStateChange Event to set the Video URL, this causes problems as a result of re-entry problems with WMP - see other posts for further explanation on my last comment: here is a good one and another here. Hope this helps!

这篇关于axWindowsMediaPlayer:循环播放时出现黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆