我创建了一个具有axWindowsMediaPlayer控件的Windows应用程序。我还没有在上面创建播放列表,但我已经将.mp4文件存储在特定位置。我通过路径到我的下一个视频在媒体结束了状态。第一次,玩家收到正确的路径和播放。但是对于第二个视频,我只能看到一个黑屏,尽管播放器收到了正确的播放路径。
以下是我的“媒体终止状态”代码:
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 (就绪状态)之后获得了正确的路径。我做错了什么?
编辑1:我发现当我当前的视频进入媒体结束状态后,播放机停止播放。即使我写了axWindowsMediaPlayer.ctlControls.play();,它也不会影响媒体播放器。这是axWindowsMediaPlayer中的一个bug吗?
发布于 2016-12-08 17:54:17
我以前也遇到过这个问题。最有可能的原因是,在播放状态仍在更改时,您正在发出命令axWindowsMediaPlayer.ctlControls.play(); (在Media结束之后,它将更改为Ready状态)。如果在播放状态更改时向玩家发送命令,则不会执行任何操作。导致您的错误的另一个可能原因是,有时需要将媒体状态9(转换)包含在if(e.newState == 8)中,以便您拥有if(e.newState == 8 | e.newState==9)。我也遇到过这样的情况,那就是它没有出现在8州(媒体结尾),可能是因为它发生得非常快,而且过渡到了过渡阶段--对这个原因还不完全确定,但我有一个球员因为这种情况而没有转移到播放列表中的下一个视频。为了解决这个问题,我做了如下事情:
if (e.newState == 8 | e.newState== 9 | e.newState== 10)
{
if (e.newState == 8)
{ //Insert your code here
}这将略有不同,取决于您正在努力实现什么。另一件需要注意的事情是使用PlayStateChange事件设置视频URL,这会导致WMP重新输入问题--请参阅其他帖子,以进一步解释我的上一条评论:here is a good one和another here。希望这能有所帮助!
https://stackoverflow.com/questions/34677126
复制相似问题