【问题标题】:WMP library multiple files added to listboxWMP 库多个文件添加到列表框
【发布时间】:2017-03-06 16:02:04
【问题描述】:

我正在使用 wmp 库创建 MP3 播放器。我想将多个文件添加到我的歌曲所在的列表框中。但不幸的是,尽管选择了不止一首,但我只添加了一首歌曲。我找不到我的错误。

        openfile.FileName = String.Empty;
        openfile.InitialDirectory = "D:\\";
        openfile.Filter = "MP3 Files(*.mp3)|*.mp3";
        openfile.RestoreDirectory = true;
        openfile.Multiselect = true;

        if (openfile.ShowDialog() == DialogResult.OK)
        {
            pictureBoxEqualizer.Visible = true;
            listBoxSongs.Items.Clear();
            if (MediaPlayer.currentPlaylist.name != "myplaylist")
            {
                WMPLib.IWMPPlaylist songs = MediaPlayer.playlistCollection.newPlaylist("myplaylist");
                WMPLib.IWMPMedia media;
                if (!playlist.Contains(openfile.SafeFileName))
                {

                        playpath.Add(openfile.FileName);
                        foreach (string file in playpath)
                        {
                            timer.Enabled = true;
                            media = MediaPlayer.newMedia(file);
                            songs.appendItem(media);
                        }
                        MediaPlayer.currentPlaylist = songs;
                        WMPLib.IWMPMedia current = MediaPlayer.currentPlaylist.get_Item(curr);
                        MediaPlayer.controls.playItem(current);

                        playlist.Add(MediaPlayer.currentMedia.getItemInfo("Artist") + " - " + MediaPlayer.currentMedia.name);


                    }
                    {
                        MessageBox.Show("Error!" + ex.Message,
                        "Error message!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("The song is already in the list");
                }  }
            else
            {
                if (!playlist.Contains(openfile.SafeFileName))
                {
                        WMPLib.IWMPPlaylist songs = MediaPlayer.currentPlaylist;
                        WMPLib.IWMPMedia media;
                        playpath.Add(openfile.FileName);
                        media = MediaPlayer.newMedia(openfile.FileName);
                        songs.appendItem(media);
                        MediaPlayer.currentPlaylist = songs;
                        WMPLib.IWMPMedia current = MediaPlayer.currentPlaylist.get_Item(curr);
                        MediaPlayer.controls.playItem(current);

                        playlist.Add(MediaPlayer.currentMedia.getItemInfo("Artist") + " - " + MediaPlayer.currentMedia.name);

                    }
                    {
                        MessageBox.Show("Error!" + ex.Message,
                        "Error message!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("The song is already in the list");
                }
                listBoxSongs.Items.Clear();

                foreach (string item in playlist)
                {
                    listBoxSongs.Items.Add(item); 
                }
                }
                listBoxSongs.SetSelected(curr, true);
                curr++;

        Title();

【问题讨论】:

    标签: c# winforms listbox wmp


    【解决方案1】:
                OpenFileDialog FileDialog = new OpenFileDialog();
                FileDialog.Multiselect = true;
                if (FileDialog.ShowDialog() == DialogResult.OK) ;
                {
                    fi = FileDialog.SafeFileNames;
                    pt = FileDialog.FileNames;
                    for (int i = 0; i < fi.Length; i++)
                    {
                        listBox1.Items.Add(fi[i]);
                    }
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 2021-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多