I believe many of my friends want to use C # to play games and other games. Of course, it is inevitable to play some audio files or video files. If DirectX is installed on your computer, this folder is usually found in c: \ windows \ Microsoft. NET.
This is the use of DirectX programming must use a few DLL files, it is very important! If you want to know what it contains
You can create a new windowsform project, include these DLL files, and view them using the Object Browser in. Net to know which functions are included.
After the player is included, we can start to develop our player.
Add a button button1, double-click it, and then addCode
Code
Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. LINQ;
Using System. text;
Using System. Windows. forms;
Using Microsoft. DirectX. audiovideoplayback;
Namespace Windowsformsapplication1
{
Public Partial Class Form2: Form
{
Audio audio = Null ;
Public Form2 ()
{
Initializecomponent ();
}
Private Void Button#click ( Object Sender, eventargs E)
{
Openfiledialog dialog1 = New Openfiledialog ();
Dialog1.title = " Browse to find sound file to play " ;
Dialog1.initialdirectory = @" C :\ " ;
Dialog1.filter = " WAV Files (*. wav) | *. wav " ;
Dialog1.filterindex = 2 ;
Dialog1.restoredirectory = True ;
Audio = New Audio (dialog1.filename, True );
}
}
}
You can call methods such as audio. Stop () and audio. Pause. You can see a lot of methods you need using the Object Browser.
If you study it carefully, you can make a satisfactory player! Success!