Oct 21, 2011

Writing Your First Media Application

We'll start with a blank Windows application project and drop the Windows Media Player control on the form. The Windows Media Player control should be in the Windows Forms section of the toolbox (see Figure 1). If it isn't there, right-click the toolbox and select Add/Remove Items. In the Customize Toolbox dialog box, click the COM Components tab, scroll down to the end of the list, and select the control to add it to the toolbox (see Figure 2).
Figure 1: The Windows Media Player control.

Figure 2 The Customize Toolbox dialog box.

Now that the control is available, drag it onto the form so you can get started working with it. When you add the control to the form, AxWMPLib (the control) and WMPLib (the core library) are added as references. Both are required.
Not surprisingly, the control looks like the guts of the Windows Media Player, as shown in Figure 3.
Figure 3 Our form with the control in place.

For a simple example, let's play an arbitrary media file in the form's Load event. To add a handler for this event, double-click the form's title bar. In the handler, write a single line to play the file:
void Form1_Load(object sender, EventArgs e)
 axWindowsMediaPlayer1.URL = @"c:\writing\wmp .net\sample\sample.avi";
Setting the URL property causes the control to load and play the selected file or URL. Our new media player application looks like Figure 4
Figure 4 The player in action.
A complete reference to the control and all its methods, events, and properties is available on MSDN.


Post a Comment

Nam Le © 2014 - Designed by Templateism.com, Distributed By Templatelib