我正在尝试创建一个视频播放器,使用AxWindowsMediaPlayer一个接一个地播放一组视频。它目前在给定集合中播放一个视频,但不播放其他视频。我正在尝试实现下面示例链接中显示的方法,以便创建由PlayStateChange属性的案例8触发的自动播放方法,"媒体完成播放。"但是,即使是一个视频也不是这样播放的。
https://msdn.microsoft.com/en-us/library/windows/desktop/dd562460(v=vs.85).aspx
如果需要进一步解释,请告诉我,我很乐意详细说明。我非常感谢有关为什么这种方法不起作用的任何见解,我对C#相对较新,并没有完全掌握代表的所有复杂性。我是否需要实现for循环以滚动浏览视频数据库,在此处称为it.video?这是我的代码:
public void playItem(Item it)
{
player.CreateControl();
player.Enabled = true;
player.enableContextMenu = false;
player.uiMode = "none";
player.Name = "player";
player.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);
player.URL = it.video;
}
void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (p_onset)
{ player.Ctlcontrols.play(); }
else if (e.newState == 8) // Media Finished
{
PlayNext();
}
else
{
player.Ctlcontrols.play();
if (!Vars.playOne)
{ PlayNext(); }
}
}
使用BeginInvoke更新代码,需要以某种方式实现EndInvoke:
public void playItem(Item it)
{
WMPLib.IWMPMedia media;
WMPLib.IWMPPlaylist playlist = player.playlistCollection.newPlaylist("myplaylist");
for (int x = 0; x < _presented.count; x++)
{
media = player.newMedia(_presented.getItem(x).video);
playlist.appendItem(media);
}
player.currentPlaylist = playlist;
player.PlayStateChange += player_PlayStateChange;
}
private void player_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (e.newState == 8)
{
this.player.BeginInvoke(new Action(() =>
{
if (p_onset)
{
player.Ctlcontrols.play();
}
else
{
if (!Vars.playOne)
{
//playQueue++;
//PlayNext();
}
}
}));
}
}
答案 0 :(得分:0)
实现我的特定目的的最佳方式是使用播放列表方法。延迟代码似乎会导致问题。这是我的解决方案:
public void playItem(ItemsPool it)
{
player.CreateControl();
player.Enabled = true;
player.enableContextMenu = false;
player.uiMode = "none";
player.Name = "player";
player.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
WMPLib.IWMPMedia media;
WMPLib.IWMPPlaylist playlist = player.playlistCollection.newPlaylist("myplaylist");
for (int x = 0; x < it.count; x++)
{
media = player.newMedia(it.getItem(x).video);
playlist.appendItem(media);
}
player.currentPlaylist = playlist;
if (p_onset)
{ player.Ctlcontrols.play(); }
else
{
if (!Vars.playOne)
{ PlayNext(); }
}
}