How to play a particular item from media play list?

Refresh

March 2019

Views

1.8k time

1

I am using windows media player in windows forms application. I have 10 media items in my playlist. foo, foo1,foo2,foo3 ....

Now my playlist is playing lets say foo1. Now on button click I want to play item foo6. How do I play this ? i.e. how do I change my current playing item too foo6 ?

If this is not clear please comment, I will add more information.

Edit: Following is the code for creating a new playlist.

WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass();
playlist = WMPLeft.playlistCollection.newPlaylist("myplaylist1");
for (int i = 0; i < FOO.Length; i++)
{
    media = WMPLeft.newMedia(FOO[i]);                          
    playlist.appendItem(media);  
}

What I want is something like this

WMPLeft.playlist.Item(3).play();

This is wrong. But this is the kind of code I want.

1 answers

2

After much research I have found this msdn link which shows how to do what I wanted.

// Declare a variable to hold the position of the media item 
// in the current playlist. An arbitrary value is supplied here.
int index = 3;

// Get the media item at the fourth position in the current playlist.
WMPLib.IWMPMedia media = player.currentPlaylist.get_Item(index);

// Play the media item.
player.Ctlcontrols.playItem(media);

LINK to MSDN