Question

I have added the playlist names from a directory in a ListBox using LinkLabel at run time but now I want that when I click on the LinkLabel of that playlist, the playlist should run and play the songs.

I have no idea about how to give the path or link to the playlist in the link label and how to start playing it.

This is my code, playlistviewbar is a ListBox:

string[] array1 = Directory.GetFiles(@"C:\Users\LENOVO\Music\Playlists","*.wpl");
int yforlbl =5;
LinkLabel[] lblplayName = new LinkLabel[array1.Length];
for (int i = 0; i < array1.Length; i++)
{
    array1[i] = Path.GetFileName(array1[i]);

    lblplayName[i] = new LinkLabel();
    lblplayName[i].Text = array1[i];

    lblplayName[i].Location = new Point(0,yforlbl);          
    playlistviewbar.Controls.Add(lblplayName[i]);

    yforlbl += 23;
}
Was it helpful?

Solution 2

ok i got it in the for loop the double click event is like this and using getbyname mathod get the playlist and set it to current playlist

           lblplayName[i].DoubleClick += (senders, es) =>
           {

               LinkLabel label = (LinkLabel)senders;
               string PlayListFile = label.Text;

               try
               {

                   WMPLib.IWMPPlaylist list = axWindowsMediaPlayer1.playlistCollection.getByName(PlayListFile).Item(0);

                   axWindowsMediaPlayer1.currentPlaylist = list;
               }
               catch
               {
                     //exception handling code
               }
           };

OTHER TIPS

In the LinkLabel's Click event handler, you can do something like this:

private void LinkLabel_Click(object sender, System.EventArgs e)
{
    LinkLabel label = (LinkLabel)sender;
    string PlayListFile = label.Text;
    Process.Start(PlayListFile);
}

As *.wpl files are associated with Windows Media Player, it should start right away. You can find more info about the Process.Start method on MSDN.

If you want to embed the MediaPlayer control in your application, then you can have a look at this article.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top