0

I have code which loads a playlist and plays videos one after another, triggered by the PlayStateChange event of AxWindowsMediaPlayer. After reading several examples, I implemented BeginInvoke in order to delay the code while the videos play. It seems as if I need to implement EndInvoke because I am having functionality issues with my code continuing after the videos are played. How should I go about this? I could not figure it out from the posted examples and MSDN guides. Here is my code:

        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
           }
         }
Harrison
  • 57
  • 11
  • is play() asynchronous? – Mike_G Sep 23 '16 at 17:42
  • This method is from: http://stackoverflow.com/questions/18577063/function-call-only-works-when-messagebox-show-is-included/18577936#18577936 – Harrison Sep 23 '16 at 18:02
  • However, they don't need EndInvoke in that case. I have clickable images that are displayed immediately after the videos are played but since EndInvoke isn't called, the images are frozen on the screen – Harrison Sep 23 '16 at 18:03
  • @Mike_G Yes I am pretty sure it is asynchronous, BeginInvoke makes it run asynchronously at least – Harrison Sep 23 '16 at 19:14

0 Answers0