7

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
    }
}
a1204773
  • 6,923
  • 20
  • 64
  • 94
  • so far you have code that will open a Dialog, now what you need is a way to hold / load the selected file(s) to a song play list List for example.. add a button to the winform and on the button click add the code that you have above .. what is the ext of the files that you want to load..? also you want to add a Pause button and a button called Play.. so perhaps you could show or explain a bit more of your overall architecture that you would like to achieve – MethodMan Dec 28 '12 at 02:37
  • this site can is a good site to start reading as well http://msdn.microsoft.com/en-us/library/windows/desktop/dd564582%28v=vs.85%29.aspx – MethodMan Dec 28 '12 at 02:40
  • This site will be a good place to start as well in fact this could be your answer.. if not try doing a google search there are tons of examples out there trust me.. that's how I found you these examples http://stackoverflow.com/questions/694912/window-media-player-in-c-sharp – MethodMan Dec 28 '12 at 02:44
  • Thank you for the last link it helped a lot – a1204773 Dec 28 '12 at 03:00

2 Answers2

15

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();
Community
  • 1
  • 1
a1204773
  • 6,923
  • 20
  • 64
  • 94
1
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

Pranesh Janarthanan
  • 1,134
  • 17
  • 26