Use Windows Media Player in .NET

Intro to incorporating the player in apps.

This Content Component encountered an error

The short attention span of television watchers is as important to your applications as it is to the TV networks, with multimedia applications becoming more the rule than the exception. Users increasingly expect slick, media-rich applications. So how do you jump on the media train without becoming an expert in codecs, streaming, and compression technologies? This tip, excerpted from InformIT, will get you started.

The short attention span of television watchers is as important to your applications as it is to the TV networks, with multimedia applications becoming more the rule than the exception. Users increasingly expect slick, media-rich applications. So how do you jump on the media train without becoming an expert in codecs, streaming, and compression technologies? Well, let me show you.

To get started, you need Windows Media Player 9.0 installed on your development machine. You also need the Windows Media Player SDK.

Be sure to get the Windows Media Player SDK, not the Windows Media Services SDK; they're very different beasts.

After you download the SDK, install it anywhere that's convenient. The SDK installs a couple of interesting features:

  • Primary Interop Assemblies (PIA) for the Windows Media Player
  • Windows Media Player control for use in Visual Studio

Now that the stage is set, let's create your first media-savvy 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. 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.

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.

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:writingwmp .netsamplesample.avi";
}

Setting the URL property causes the control to load and play the selected file or URL.

A complete reference to the control and all its methods, events, and properties is available on MSDN.


To read the entire article from which this tip comes, click over to InformIT. No registration required. You don't give any of your information; you just get lots of good info from the site.


This was first published in December 2003
This Content Component encountered an error

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close