C# using windows forms how can I make media player to play MPEG2 files ?
Hello, I am trying to make a media player that can play MPEG2 files. I already made one using windows media player tool from .COM components of C# in .NET4.5 how can I make it support MPEG2 files for playing. This is my 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);
}
}
}
}
Re: C# using windows forms how can I make media player to play MPEG2 files ?
What version of WindowsMediaPlayer are you using? Can you play the mpeg2 files in the media player application (outside of your code)?
Re: C# using windows forms how can I make media player to play MPEG2 files ?
Quote:
Originally Posted by
Arjay
What version of WindowsMediaPlayer are you using? Can you play the mpeg2 files in the media player application (outside of your code)?
What I am seeing from COM components Windows Media Player its using the version 1.0
I am using visual studio 2012.
I cannot play it inside or outside of code.
Re: C# using windows forms how can I make media player to play MPEG2 files ?
Quote:
Originally Posted by
rumman0786
What I am seeing from COM components Windows Media Player its using the version 1.0
I am using visual studio 2012.
I cannot play it inside or outside of code.
Because you can't play the file outside the code, it tells me that the version you are using is either too old or you need to have the correct codec to play the file.
Re: C# using windows forms how can I make media player to play MPEG2 files ?
Quote:
Originally Posted by
Arjay
Because you can't play the file outside the code, it tells me that the version you are using is either too old or you need to have the correct codec to play the file.
I thats what I am trying to learn. How do I include a codec in WMP with code. Can you help me ?
Re: C# using windows forms how can I make media player to play MPEG2 files ?
Quote:
Originally Posted by
rumman0786
I thats what I am trying to learn. How do I include a codec in WMP with code. Can you help me ?
How do you know your problem is because of a missing codec? At any rate, if it is the problem, you will have to detect the presence of the codec you need, and install it if necessary in your app's setup program.
Re: C# using windows forms how can I make media player to play MPEG2 files ?
Quote:
Originally Posted by
Arjay
How do you know your problem is because of a missing codec? At any rate, if it is the problem, you will have to detect the presence of the codec you need, and install it if necessary in your app's setup program.
Okay , so I installed K-Lite codec in my laptop. and after that I can play the files I wanted to in WMP both inside and outside the code.
Now my question is If my project file is run in some other pc will it be able to play MPEG or other file formats ? or on those pcs there has to be this codecs installed ?
Re: C# using windows forms how can I make media player to play MPEG2 files ?
Quote:
Originally Posted by
rumman0786
Okay , so I installed K-Lite codec in my laptop. and after that I can play the files I wanted to in WMP both inside and outside the code.
Now my question is If my project file is run in some other pc will it be able to play MPEG or other file formats ? or on those pcs there has to be this codecs installed ?
Don't know for sure, but my guess would be it will need the codecs installed. But don't take my word for it - test it yourself.
If I were doing this work, I would detect if the codec was present on the target machine in my app's setup program and install the codec if necessary.
Another option might be to convert the mpeg2 file into a format that plays without any additional codecs.
Re: C# using windows forms how can I make media player to play MPEG2 files ?
Quote:
Originally Posted by
Arjay
Don't know for sure, but my guess would be it will need the codecs installed. But don't take my word for it - test it yourself.
If I were doing this work, I would detect if the codec was present on the target machine in my app's setup program and install the codec if necessary.
Another option might be to convert the mpeg2 file into a format that plays without any additional codecs.
can you give any direction on how I can do it ?