Embedding Windows Media in Windows Forms App

G

Guest

Hi. I want to embed a Windows Media control in a Windows Forms form but I'm a
little confused about the right way to do it. I want to set it up so that it
will use the version of Windows Media that the user has on his/her computer,
rather than needing to include the entire Windows Media package along with my
app. What's the right way to do this and how to I handle the idea that I need
a certain minimum version of the Windows Media Control but I have no problem
with more recent versions.

Alex
 
L

Linda Liu [MSFT]

Hi Alex,

When we drag&drop a Windows Media Player COM object from Toolbox onto a
form, VS generates wrapper classes for the COM object automatically and we
use the Windows Media Player COM object through the wrapper classes.

To get the application to run appropriately, we must keep the dll files
that contains the wrapper classes, i.e. AxInterop.WMPLib.dll and
Interop.WMPLib.dll, in the same directory as the application.

Note that the AxInterop.WMPLib.dll and Interop.WMPLib.dll files aren't the
entire Windows Media package. In fact, when the application is run on a
machine other than the development computer, the application uses the
Windows Media player installed on that machine.

We could use the versionInfo property of the AxWMPLib.AxWindowsMediaPlayer
wrapper class to get the version of Windows Media Player currently
installed on the machine. The following is a sample.

MessageBox.Show(this.axWindowsMediaPlayer1.versionInfo);

So if you have a requirement on the minimum version of the Windows Media
Player, you could make use of the versionInfo property.

Hope this helps.
If you have any question, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thanks. I'm still a little confused about one thing: Can you help me be VERY
clear on EXACTLY what to add to my project and how? In VS 2005, on a Windows
Form, how do I add the Windows Media object, exactly. Also, the list of COM
objects related to Windows Media is very long. I am confused as to EXACTLY
which one of these objects I have to add. Can you step me through the exact
steps, just to the point where I have a WM object on my form which I can then
access from my C# code, etc.? Thanks a lot!

Alex
 
M

msnews.microsoft.com

Alex,

When you add the object to your toolbox you are looking for COM component
"Windows Media Player" which is associated with
<SystemRoot>/System32/wmp.dll.

Randy L
 
L

Linda Liu [MSFT]

Hi Alex,

Thank you for your reply.

The following is the walkthrough to use a Windows Media Player COM
component in a WinForms application.

1. If the Windows Media Player COM component is not present in the Toolbox,
right-clikc on the Toolbox and choose 'Choose Items'. In the 'Choose
Toolbox Items' dialog, switch to the 'COM Components' tab. Navigate to
'Windows Media Player' (whose path is 'c:\Windows\system32\wmp.dll') and
select the checkbox before this item. Press OK.

2. Drag&drop the Window Media Player COM component from Toolbox onto a
form. At this time, VS IDE will generate wrapper classes for this COM
component automatically. COM components are not managed, so we couldn't use
them directly in .NET applications.

If you expand the Reference node under the project node in the Solution
Explorer, you should see two references called 'AxWMPLib' and 'WMPLib' are
added.

3. You may add the following code to the form:

private void Form1_Load(object sender, EventArgs e)
{
// the 'axWindowsMediaPlayer1' is the name of the Windows Media Player
COM component on the form
MessageBox.Show(this.axWindowsMediaPlayer1.versionInfo);
this.axWindowsMediaPlayer1.URL = "the path of the video/audio file";
}

4. Build the project. Go to the bin\debug folder of the application and you
should see two files called 'AxInterop.WMPLib.dll' and
'Interop.WMPLib.dll', which are the dll files that contain the wrapper
classes for the Windows Media Player COM component.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top