CSharp .Net Tutorial: Audio and Video with Windows Media Player

James Cloud
Introduction

Whether you are making a media player or if you simply would like to display audio or video inside your CSharp .Net application, Windows Media Player is a fast, reliable and easy to implement solution.

The steps given below will show you how to add the Windows Media Player control to your project and then, load and play a media file.

Step One - Adding the Windows Media Player Control

To use the Windows Media Player in your Window's Form control, you will need to add a reference to wmp.dll to your project.

First, click the 'Project' menu and select the 'Add Reference...' button. Next, switch to the 'COM' tab and search for the entry entitled, 'Windows Media Player', double click this entry.

Windows Media Player is now referenced, but it still needs to be added to the controls toolbox. In the toolbox, right click a blank area and select the 'Choose Items' button. Go to the 'COM Components' tab, find and check 'Windows Media Player' and press OK.

The Windows Media Player control will now be available in the toolbox. Click and drag this control on to your desired form and set the size and properties accordingly.

Step Two - Loading Media Files

With the Windows Media Player control added to the form and ready for use, go into your form's code view. Go to the function where you would like to load a media file and use this source code,

axWindowsMediaPlayer1.URL = @"C:\Mediafile.avi";
axWindowsMediaPlayer1.Ctlcontrols.play();

You will need to replace the 'axWindowsMediaPlayer1' with the name of your Windows Media Player control. Also, replace the 'C:\Mediafile.avi' with path to the media file. The code will automatically load the given media file and start playing it.

Conclusion

There are many option and function included in the Windows Media Player control that will allow you customize it according to your needs and desires. For more information on these abilities check out Microsoft's MSDN entry for the Windows Media Player Control located here,

http://msdn.microsoft.com/en-us/library/dd563946%28v=VS.85%29.aspx

Published by James Cloud

I like to program and do basically anything that has to do with technology and computers.  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.