C # Call the Windows Media Player Program

Source: Internet
Author: User

Media Player.

 

 

The method is as follows:

1. Call the COM component of media player. For example:

 

 

 

 

2. the Windows Media Player control is displayed in the toolbox. For example:

 

3. Drag related controls to the form, such as the first image. And writeCode. The related code is as follows:

Using System. IO;

Namespace Mymedia
{
Public   Partial   Class Formplayer: Form
{
Public Formplayer ()
{
Initializecomponent ();
// Select File events
Btnfile. Click + =   New Eventhandler (btnfile_click );

//Exit
Btnexit. Click+ = NewEventhandler (btnexit_click );
}

///   <Summary>
/// Select File event Method
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Void Btnfile_click ( Object Sender, eventargs E)
{
Try
{
Openfiledialog opfplayer =   New Openfiledialog ();
Dialogresult drplayer = Opfplayer. showdialog ();
If (Drplayer = Dialogresult. OK)
{
String Sfile = Opfplayer. filename;
// Playback file address (wmpplayer is the playback control dragged into the form)
Wmpplayer. url = Sfile;
}

}
Catch(Exception ex)
{
ThrowEx;
}

}

///   <Summary>
/// ExitProgram
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Void Btnexit_click ( Object Sender, eventargs E)
{
Application. Exit ();
}
}
}

 

Run the program, select a file, and your media player program can play music!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.