Hi,
You have learned to create a Music Player in C#, now here's a tutorial for creating your own Media Player in C# and press OK.
Steps
1. Open Visual Studio -> New Project -> Windows Form Application with Name
Media Player.
2. Your project will load with an empty form. Now add Windows Media Player Control
to the toolbox (since Windows Media Player Control is not available in the
Toolbox by default).
3. Steps to load Windows Media Player Control (COM component) into Toolbox.
- Right Click on General tab (or any other tab) in the Toolbox and select Choose Items
- Now select COM Components tab and check Windows Media Player and click OK.
4. Windows Media Player control will appear in the Toolbox. Now drag it to your form
and resize it.
Also add 1 button and OpenFileDialog to the form.
5. Design the form as shown in the below figure.
6. Click on the Windows Media Player control and press F4 to get the Properties
dialog box. Change the Dock to Fill. By doing so, the control will stretch to fit in
the form. This will be useful if the user resizes the window while your player is
running.
7. Now select the button and get the Properties dialog box and change its:
Name - btnbrowse
Text - Browse
Also change the Anchor to Bottom,Right as shown in the below figure.
8. Now double click on the Browse button and update the code with the below one.
Form1.cs
using System;
using System.Windows.Forms;
namespace Media_Player
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnbrowse_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
openFileDialog1.Filter = "(mp3,wav,mp4,mov,wmv,mpg)|*.mp3;*.wav;*.mp4;*.mov;*.wmv;*.mpgn|all files|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
axWindowsMediaPlayer1.URL = openFileDialog1.FileName;
}
}
}
}
See the Screenshot
9. Rebuild and Run the project. You will get your own Media Player. Browse for video
files and Enjoy Watching.
See Also
No comments:
Post a Comment