Altimus Prime
Altimus Prime

Reputation: 2337

How do you clear a windows media player playlist programmatically c#

My program uses windows media player in C# so that I can play almost any sound file. Some sounds need to play in succession, one after the other. The only way I could think to do that was with playlists, but I can't figure out how to clear the playlist between calls to the windows media player.

How can I play sounds, one after the other, in windows media player, without running into problems from previous playlists?

Thanks

My code:

WMPLib.IWMPPlaylist playlist = axWindowsMediaPlayer1.playlistCollection.newPlaylist("myplaylist");

WMPLib.IWMPMedia media;

foreach (string question in questionURL)
   {
       media = axWindowsMediaPlayer1.newMedia(question);
       playlist.appendItem(media);
       media = axWindowsMediaPlayer1.newMedia(answer);
       playlist.appendItem(media);

       axWindowsMediaPlayer1.currentPlaylist = playlist;
       axWindowsMediaPlayer1.Ctlcontrols.play();
       axWindowsMediaPlayer1.playlistCollection.remove(playlist);\\one of my many failed attempts at clearing the playlist. It doesn't throw an error, it doesn't clear the playlist either.
   }

Upvotes: 0

Views: 5822

Answers (2)

Ravi Kant
Ravi Kant

Reputation: 11

This is the exact solution if you want to clear your playlist.

playlist.clear();
axWindowsMediaPlayer1.currentPlaylist = playlist; 

Upvotes: 1

Idle_Mind
Idle_Mind

Reputation: 39152

See PlaylistCollection.remove().

So I think you could remove the playlist with:

axWindowsMediaPlayer1.playlistCollection.remove("myplaylist");

Then simply create it again:

playlist = axWindowsMediaPlayer1.playlistCollection.newPlaylist("myplaylist");

Upvotes: 1

Related Questions