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
}
}