0
Answer

C# using WinForms how do I play MPEG2 by using WMP library?

rumman ashraf

rumman ashraf

11y
1.6k
1
Hello ,
 I am a C# beginner. I am trying to make a media player that can play MPEG2 files.I have used Windows Media Player COM component to make a basic media player. Now I need to modify it so that it can play MPEG2 files. Any suggestion or links that can help me in this matter would be great.
 
Code :

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

namespace Media_Player_Basic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Title = "Open";
            open.Filter = "All Files|*.*";
            try
            {
                if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    BasicWindowsMediaPlayer.URL = (open.FileName);
                }
            }
            catch (ArgumentException ex) {
                MessageBox.Show(ex.Message.ToString(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Massive Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}