0

I have a list of videos, supposed to run in WMP control in endless loop (with some specialties like shuffle after playing one block, some special videos on demand...). After a while which is not determined (something about 20 minutes), the control remains black, showing no video, having no play state changes anymore.

I found out that usually there is a certain sequence of actions and events (see code below). And if this sequence is broken and WMP goes directly from wmppsPlaying to wmppsReady, the point of no return is reached: My only solution is to restart the whole exe. (I also tried disposing and re-creating WMP object as well as disposing and re-creating the whole form object). As found here and referenced here and here, I also did not do any actions directly in event handler, but invoking them for delay.

private void Play(string file)
{
    this.player.Ctlcontrols.stop();
    this.ClearPlaylist();
    this.player.stretchToFit = true;
    this.player.uiMode = "none";
    this.player.URL = file; 
    this.player.Ctlcontrols.playItem(this.player.Ctlcontrols.currentItem);
    this.player.Ctlcontrols.play();
}

private void ClearPlaylist()
{
    // try to avoid memory or state issues
    IWMPPlaylistArray playlist = this.player.playlistCollection.getAll();
    for (int i = 0; i < playlist.count; i++)
    {
        this.player.playlistCollection.remove(playlist.Item(i));
    }
}

private void player_PlayStateChange(object sender, _WMPOCXEvents_PlayStateChangeEvent e)
{
    /* usual sequence as logged:
     * x-1: last/running video
     * x:   next video to play
     * x+1: video after that...

     * GetNextVideo x
     * 9            x-1
     * 10           x-1
     * 9            x-1
     * play Video   x
     * 10           x
     * 3            x
     * 8            x
     * GetNextVideo x+1
     * 9            x
     * 10           x
     * 9            x
     * play Video   x+1
     * 10           x+1
     * 3            x+1
     * 8            x+1

     */
    this.BeginInvoke((MethodInvoker)(() => this.VideoPlayerStatusChange(e.newState)));
}

private void VideoPlayerStatusChange(WMPPlayState newState)
{
    if (!this.m_Restart && !this.m_IgnorePlayerEvent)       // ignore cases with change state, but require no further action
    {
        if (this.m_LastPlayState == WMPPlayState.wmppsPlaying && newState == WMPPlayState.wmppsReady)
        {
            // weird: After that, player remains black and blocked, nothing happens any more
            // what can be done now?
            // here I do a restart of exe. which cannot be the best solution ever...
        }
        else
        {
            if (newState == WMPPlayState.wmppsMediaEnded || newState == WMPPlayState.wmppsStopped)
            {
                // video finished normal way: GetNextVideo and play that
                this.PlayNextVideo();
            }
            if (newState == WMPPlayState.wmppsReady && !String.IsNullOrEmpty(this.player.URL))    // teilw. s. o.
            {
                // player is ready, video loaded: play it.
                this.player.Ctlcontrols.play();
            }
        }
        this.m_LastPlayState = newState;
    }
}

private void PlayNextVideo()
{
    Video video = this.GetNextVideo();
    if (video != null)
    {
        this.Play(video);
    }
}

And there might be some more cases, in which the player hangs. (Currently I have an overnight-test running to figure out the next point of no return.)

How can I avoid WMP hanging? If it hangs, how can I make it run again (without restarting the exe)? Did I miss something else, which avoids that strange behaviour?

Mate
  • 241
  • 1
  • 2
  • 11
  • You should log all your VideoPlayerStatusChange state changes to make sure that you aren't just sitting around waiting for a state that won't happen. Lots of edge-triggering here. It would be nice to know you're not missing conditions because the state was wmppsBuffering or something. Can't tell if WMP is hanging or if you're just not handling state changes correctly. – Wyck Aug 13 '19 at 19:50
  • All states are logged, that's the repeating sequence: wmppsReady > wmppsTransitioning > wmppsTransitioning > wmppsPlaying > wmppsMediaEnded > wmppsTransitioning > wmppsStopped > wmppsTransitioning > wmppsReady > wmppsTransitioning > wmppsTransitioning – Mate Aug 14 '19 at 07:44

0 Answers0