7

我有一个OpenFileDialog具有Multiselect = true. 现在我想将每个文件添加到 Windows 媒体播放器播放列表,但我不知道如何做到这一点,并且互联网上没有很好的例子。

if (ofdSong.ShowDialog() == DialogResult.OK)
{
    foreach (string file in ofdSong.FileNames)
    {
        //Code to add file to the playlist
    }
}
4

2 回答 2

15

在给我示例链接的DJ KRAZE编写该示例的 JayJay 的帮助下,这里是解决方案。

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();
于 2012-12-28T02:59:15.373 回答
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;
 }

播放多个项目:复制和粘贴并享受

于 2016-05-04T05:23:36.127 回答