0

I am coding an application that displays some still images in a picture box control in sequence (slideshow), and then play several MP4 files using the windows media player WMP control. The video files are dumped into a folder and a playlist is created on the fly on each cycle so that if the contents of the folder change the new playlist will also be fresh.

A problem has surfaced and I have researched this but cannot find out whats wrong in my code as the suggested fixes to not seem to work.

Given: My slideshow & videos play correctly. But every time it plays the videos a new 'myplaylist.wpl' file is created in the local "..\Music\Playlists" folder and they accumulate in that folder with numbered extensions, ex: myplaylist(1), myplaylist(2), myplaylist(3), myplaylist(4), myplaylist(5), etc etc until myplaylist(1999)

At that point, when there are 2000 (including the base file 'myplaylist') WMP crashes with a catastrophic error.

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) but none of them work.

This behavior is documented online in several places, and I have attempted to use the suggestions here: How to delete a windows media playlist programmatically and here Catastrophic failure (Exception from HRESULT: 0x8000FFFF) creating a playlist with axwindowsMediaPlayer

private void playVids()
    {
        try
        {
            txtVid.Text = "Playing";
            WMPLib.IWMPPlaylist playlist = wmp.playlistCollection.newPlaylist("myplaylist"); 
            WMPLib.IWMPMedia media;
            string[] vidfiles = Directory.GetFiles(SelectedVidPath,"*.*");
            {
                foreach (string file in vidfiles)
                {
                    media = wmp.newMedia(file);
                    playlist.appendItem(media);
                }
            }
            this.wmp.Visible = true;      
            wmp.uiMode = "none";
            wmp.currentPlaylist = playlist;                
        }

        catch (Exception ex)
        {               
            Logerr(ex.ToString()); //write Exception err to log
        }


    }

I am using the player_PlayStateChange event to trigger a new block of code, which only triggers when the WMP player is in a 'Ready State' - no longer using the playlist, as:

    private void player_PlayStateChange(object sender, 
 AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {            
                    switch (e.newState)
            {
                    case 10:   // Ready
                    currentStateLabel.Text = "Ready";                      
                    vidcounter++;
                    counter = 0;
                    ImageTimer.Start();
                    wmp.playlistCollection.remove(myplaylist);               
            }
        }

I expected the file to be gone after the .remove(myplaylist) is called but the file does not delete. Any insight in this would be appreciated.

user1062142
  • 119
  • 3
  • 13
  • We can't see your PlayStateChange event handler. But the issue is quite common, you can't do anything with the WMP object in that handler. Meant only to update your UI. Workaround is to use the UI's BeginInvoke() method so the code runs later, after the event is handled and the WMP object is in a safe state again. – Hans Passant Sep 05 '19 at 08:04
  • Thanks Hans. I added the PlayStateChanged event code above for you to review. Sorry should have done that from the start. I am waiting until the player is in Ready State. – user1062142 Sep 05 '19 at 11:58

0 Answers0