将EndInvoke与BeginInvoke组合用于PlayStateChange事件

时间:2016-09-23 17:30:13

标签: c# c#-4.0 begininvoke axwindowsmediaplayer

我有一些代码可以加载一个播放列表并一个接一个地播放视频,由AxWindowsMediaPlayer的PlayStateChange事件触发。在阅读了几个例子后,我实现了BeginInvoke,以便在视频播放时延迟代码。好像我需要实现EndInvoke,因为在播放视频后我的代码仍然存在功能问题。我该怎么办呢?我无法从发布的示例和MSDN指南中找到它。这是我的代码:

        public void playItem(Item 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 < _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();
                }

            }));
            //Maybe Implement EndInvoke here?  Unsure of the proper syntax for this scenario
           }
         }

0 个答案:

没有答案