In this article we will learn how we can play audio and video files in windows Application.
Today while pondering over with my friend on how we can play and video files.So, this is what we will be doing today in this article.
- Adding Windows Media Player Component
- Playing Video files in Windows Media Player
Using the code
- Create a New Windows Project in Visual Studio 2010.
- Go to tool box and Right Click on the Empty Space and select Choose Items and then to go to Com Tab and select Windows Media Player and click OK (Check Screen 1)
- Once we complete this step we will check get the Windows Media Player Control just drag and drop the control on the Windows Form.(Check Screen 2)
- Now drag and drop the Windows Media Player control that we have got,one button and one Open File Dialog on the form.The UI Will be as Screen Number 3
Screen 1 :- Adding Windows Media Player Component
Screen 2 :- Windows Media Player
Screen 3 : UI
- Once we click the browse button a file dialog box will be opened and tell us to choose the files to play
- The file type supported are mp3,wav,mp4,mov,wmv,mpg
- Once we select the files from the above extension and click ok the video will start playing
- While the video playing you can right click on the control and get more options for video setting.
Screen 4: Output
// Code behind
public partial class Form1 : Form
private void Browse_Click(object sender, EventArgs e)
ofddialog.Filter = "(mp3,wav,mp4,mov,wmv,mpg)|*.mp3;*.wav;*.mp4;*.mov;*.wmv;*.mpg|all files|*.*";
// axWindowsMediaPlayer1 is the object of the Windows Media Player class that allows to get the path
// to play the file in windows media player component
axWindowsMediaPlayer1.URL = ofddialog.FileName;
label2.Text = ofddialog.FileName;
We have used axWindowsMediaPlayer1 object of the Windows Media Player class that allows to get the path to play the file in windows media player component with its URL Method.
Note :- The windows media Player dll is available with all Windows Operating System except With Windows 8 Enterprise N Edition.To get Windows Media Player for Windows 8 Enterprise N Edition we need to download and install and update from windows update center
The Update is named as Description of the Microsoft Windows Media Feature Pack for N and KN Versions of all Windows 8 Editions
KB Number :- KB2703761
Link to Download :- http://www.microsoft.com/en-us/download/details.aspx?id=30685