Suci 0605
Suci 0605

Reputation: 61

c# how to create playlist in my media player?

how to play more than one audio/video file in my media player and create them into my playlist?

this is my code now:

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);
        }
    }
}

with this code, i just can play one file and if i would to play more i would to open file dialog again.

Upvotes: 0

Views: 4750

Answers (1)

Humble BustleAdobe
Humble BustleAdobe

Reputation: 46

The way that Grant mentioned shows the cue to your problem. All you need to do more is creating the playlist by the files from bukaFile.FileNames. I change the codes of your function :openToolStripMenuItem_Click as below:

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
  }
}

You could try your own ways for adding the playlist. I just show one possibility.

Upvotes: 1

Related Questions