c#如何在我的媒体播放器中创建播放列表?

时间:2016-03-31 01:07:11

标签: c# visual-studio

如何在我的媒体播放器中播放多个音频/视频文件并将其创建到我的播放列表中?

现在这是我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MediaPlayer
{
    public partial class Form1 : Form
    {
        BindingList<OpenFileDialog> openFileDialog1 = new BindingList<OpenFileDialog>();
        private Image gambar;
        public Form1()
        {
            InitializeComponent();
            String filterfile = "(*.mp3; *.wav; *.mkv; *.avi; *.mp4; *.mkv; *.3gp; *.flv; *.ifo; *.vob;)|*.mp3; *.wav; *.mkv; *.avi; *.mp4; *.mkv; *.3gp; *.flv; *.ifo; *.vob;";

            OpenFileDialog bukaFile = new OpenFileDialog();
            bukaFile.Filter = filterfile;
        }

        private void fileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panel1.Hide();
            pictureBox1.Hide();
            groupBox1.Hide();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog bukaFile = new OpenFileDialog();
            bukaFile.ShowDialog();

            axWindowsMediaPlayer1.URL = bukaFile.FileName;
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        public string about()
        {
            return "0605Media V.1 (suci0605 (29/12/2015 12:13AM)";
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Hide();
            panel1.Hide();
            pictureBox1.Show();
            groupBox1.Show();
        }



        private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(about());
        }

        private void exitToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }
    }
}

使用此代码,我只能播放一个文件,如果我想播放更多,我会再次打开文件对话框。

1 个答案:

答案 0 :(得分:1)

格兰特提到的方式显示了问题的提示。您需要做的更多就是通过bukaFile.FileNames中的文件创建播放列表。我更改了您的功能代码:openToolStripMenuItem_Click,如下所示:

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
  OpenFileDialog bukaFile = new OpenFileDialog();
  bukaFile.Multiselect = true;
  if (bukaFile.ShowDialog() == DialogResult.OK)
  {
     /// create playlist
     axWindowsMediaPlayer1.currentPlaylist = axWindowsMediaPlayer1.newPlaylist("aa", "");
     foreach (string fn in bukaFile.FileNames)
     {           ////add playlist from the selected files by the OpenFileDialog
            axWindowsMediaPlayer1.currentPlaylist.appendItem(axWindowsMediaPlayer1.newMedia(fn));
     }
       axWindowsMediaPlayer1.Ctlcontrols.play();        ////play
  }
}

您可以尝试自己的方式添加播放列表。我只展示了一种可能性。