How to add multiple files to a playlist
Asked Answered
M

2

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
    }
}
Maniacal answered 28/12, 2012 at 2:29 Comment(4)
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<string> 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 achieveUnreliable
this site can is a good site to start reading as well msdn.microsoft.com/en-us/library/windows/desktop/…Unreliable
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 #695412Unreliable
Thank you for the last link it helped a lotManiacal
M
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();
Maniacal answered 28/12, 2012 at 2:59 Comment(2)
Thanks it really helped, MS is sooo stupid at naming functions and logic.Clarindaclarine
what class is wmp.playlistCollection.newPlaylist, It's not recognised?Boles
S
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

Sioux answered 4/5, 2016 at 5:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.