Monday, September 26, 2016

Creating Media Player in C#

 Hi in this blog we are going to see how to create our custom media player using C#.First Create a project and add Reference "Window Media Player" under COM Section.


Add Reference:



Layout of my Form:




Click the "Add File to playlist" Button choose media file that you want to play.And then hit the play button.

Full Source Code:


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 SimpleMediaPlayerWithCsharp
{
    public partial class Form1 : Form
    {
        string path;
        
        public Form1()
        {
            InitializeComponent();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Sending the url to the Media player
            axWindowsMediaPlayer1.URL = (string)listBox1.SelectedItem;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string filename = System.IO.Path.GetFullPath(openFileDialog1.FileName);
                listBox1.Items.Add(filename);
            }
        }
        
    }
}



Download Source Code





No comments:

Post a Comment