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!