Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple files to a playlist

I have one OpenFileDialog control that has Multiselect = true. Now I want to add each file to windows media player playlist but I have no idea how to do that and there is no good example on the internet.

if (ofdSong.ShowDialog() == DialogResult.OK)
{
    foreach (string file in ofdSong.FileNames)
    {
        //Code to add file to the playlist
    }
}
like image 915
a1204773 Avatar asked Dec 28 '12 02:12

a1204773


2 Answers

With help of DJ KRAZE that gave me the example link and JayJay who wrote that example, here is the solution.

WMPLib.IWMPPlaylist playlist = wmp.playlistCollection.newPlaylist("myplaylist");
WMPLib.IWMPMedia media;
if (ofdSong.ShowDialog() == DialogResult.OK)
{
    foreach (string file in ofdSong.FileNames)
    {
        media = wmp.newMedia(file);
        playlist.appendItem(media);
    }
}
wmp.currentPlaylist = playlist;
wmp.Ctlcontrols.play();
like image 113
a1204773 Avatar answered Oct 05 '22 23:10

a1204773


private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
  var myPlayList =  axWindowsMediaPlayer1.playlistCollection.newPlaylist("MyPlayList");
  OpenFileDialog open = new OpenFileDialog();
  open.Multiselect =true;
  open.Filter = "All Files|*.*";

  if(open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
   {
     foreach(string file in open.FileNames)
       {
         var mediaItem = axWindowsMediaPlayer1.newMedia(file);
         myPlayList.appendItem(mediaItem);
       }
   }

  axWindowsMediaPlayer1.currentPlaylist = myPlayList;
 }

to play multiple items: copy and paste and enjoy

like image 30
Slahuddin Sial Avatar answered Oct 05 '22 23:10

Slahuddin Sial