0

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;
}
vidhi
  • 411
  • 1
  • 6
  • 19

2 Answers2

1

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.

Yannick Blondeau
  • 9,465
  • 8
  • 52
  • 74
  • i tried but it gives me error at `Process` and `Text`. i have also added assembly referance `System.Diagnostics.Process` but still gives error – vidhi Mar 06 '13 at 09:25
  • still it is not working after clicking on the linklable it is not playling.. can you tell me how this work? and for what wmplayer.exe is there? – vidhi Mar 06 '13 at 14:14
  • and i have used windows media player component in my player so i want to play playlist in that or to set it as media player's current playlist – vidhi Mar 06 '13 at 14:21
  • @user1970036 I've edited the code above to use the file name only. It will use the default installation of WMP on the host... – Yannick Blondeau Mar 06 '13 at 14:38
0

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
               }
           };
vidhi
  • 411
  • 1
  • 6
  • 19