How do I delete WMP Playlists after playing?

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.

c#
.net
wmp
asked on Stack Overflow Sep 5, 2019 by user1062142 • edited Sep 13, 2019 by user1062142

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0