如何创建和保存播放列表

时间:2013-02-24 10:25:12

标签: c# winforms axwindowsmediaplayer

我正在尝试使用c#.net中的Windows媒体播放器组件开发媒体播放器。这是我可以制作播放列表并将歌曲添加到播放列表的代码,播放列表的名称将显示在名为“playlistviewbar”的列表框中,然后我将此播放列表设置为当前播放列表。

但是当我运行项目和当前的平民设置时,它要求播放与玩家不匹配的媒体。它表明它有扩展名“。”它无法播放媒体

任何人都可以帮我解决这个问题,也可以帮我保存播放列表..

WMPLib.IWMPPlaylist pl;
 public WMPLib.IWMPMedia files1,paths1;
 string playListName;

    private void toolStripButton3_Click(object sender, EventArgs e)
    {
        if (listnametxt.Text == "")
        {
            playListName = "Untitled playlist";
        }
        else
        {
            playListName = listnametxt.Text;
        }
        pl = axWindowsMediaPlayer1.playlistCollection.newPlaylist(playListName);
        playlistviewbar.Items.Add(playListName);

    }

    private void toolStripButton2_Click(object sender, EventArgs e)
    {
        if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            string[] filestring=openFileDialog2.SafeFileNames;
             string[] pathstring=openFileDialog2.FileNames;
            for (int i = 0; i < filestring.Length; i++)
            {
            files1 = axWindowsMediaPlayer1.newMedia(filestring[i]);
            paths1 = axWindowsMediaPlayer1.newMedia(pathstring[i]);
            pl.appendItem(paths1);
            axWindowsMediaPlayer1.currentPlaylist =pl;
            }


        }
    }

1 个答案:

答案 0 :(得分:3)

这是代码,它对我有用:

private void button1_Click(object sender, EventArgs e)
        {
            var pl = axWindowsMediaPlayer1.playlistCollection.newPlaylist("plList");
            pl.appendItem(axWindowsMediaPlayer1.newMedia(@"D:\nosazi.wmv"));
            pl.appendItem(axWindowsMediaPlayer1.newMedia(@"D:\tasadof.mp4"));

            axWindowsMediaPlayer1.currentPlaylist = pl;
            axWindowsMediaPlayer1.Ctlcontrols.play();            
        }