|
How to play audio files by using Visual Basic .NET or Visual Basic 2005
Create a Windows Application
1. Start Microsoft Visual Studio .NET or Microsoft Visual Basic 2005.
2. On the File menu, point to New, and then click Project.
3. Under Project Types, click Visual Basic Projects.
Note In Visual Studio 2005, click Visual Basic under Project Types.
4. Under Templates, click Windows Application.
5. In the Name box, type AudioDemo, and then click OK. By default, Form1.vb is created.
Add a Windows Media Player control to the Application
1. Start Visual Studio .NET or Visual Studio 2005.
2. On the Tools menu, click Add/Remove Toolbox Items.
Note In Visual Studio .NET 2002, on the Tools menu, click Customize Toolbox.
In Visual Studio 2005, click Choose Toolbox Items on the Tools menu.
3. Click the COM Components tab, and then click Browse.
4. Locate and then click Msdxm.ocx, and then click Open.
Note Msdxm.ocx is typically located in %WINDIR%/System32, where %WINDIR% is the location of the Windows directory on your computer.
5. In the Customize Toolbox or Choose Toolbox Item dialog box, click OK. In Visual Studio .NET 2003 and in Visual Studio 2005, a WindowsMediaPlayer control is added to the toolbox. In Visual Studio .NET 2002, a MediaPlayer control is added to the toolbox.
6. In Visual Studio .NET 2003 or in Visual Studio 2005, add a WindowsMediaPlayer control to Form1. In Visual Studio .NET 2002, add a MediaPlayer control.
7. AxMediaPlayer1 is added to Form1.
Add Buttons to Control the Windows Media Player
1. Add four Button controls to Form1.
2. Click Button1.
3. In the Properties pane, change the Text property of Button1 to Load.
4. Click Button2.
5. In the Properties pane, change the Text property of Button2 to Play.
6. Click Button3.
7. In Properties pane, change the Text property of Button3 to Pause.
8. Click Button4.
9. In the Properties pane, change the Text property of Button4 to Stop.
Add an OpenFileDialog Component to Load an Audio File
Add a OpenFileDialog component to Form1.
Add Initialization Code
1. On the View menu, click Code.
2. In the "Windows Form Designer generated code" region, locate the following code:InitializeComponent()
3. Add the following code after the code that you located in step 2:' Disable the Play, the Pause, and the Stop buttons.
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
' Hide the Windows Media Player.
AxMediaPlayer1.Visible = False
more : http://msdn2.microsoft.com/en-us/library/ms379584(vs.80).aspx |