This step-by-step article describes how to play .wav sound files and system sounds by using the My namespace in Microsoft Visual Basic 2005. This article also contains a code example that illustrates the concepts that are discussed in the article.
The following list outlines the recommended hardware, software, network infrastructure, and service packs that you must have:
Microsoft Windows Server 2003, Microsoft Windows 2000, Microsoft Windows XP, or Microsoft Windows XP Service Pack 1 (SP1)
Visual Basic 2005
This article assumes that you are familiar with the following topics:
Visual Basic 2005 programming
To play .wav sound files and system sounds by using Visual Basic 2005, follow these steps:
Create a Microsoft Windows application. To do this, follow these steps:
Start Microsoft Visual Studio 2005.
On the File menu, point to New, and then click Project.
In the Project types list, click Visual Basic.
In the Templates list, click Windows Application, and then click OK.
Note By default, WindowsApplication1 is created and Form1.vb is opened in Design view.
Add two control buttons to the Form1.vb form. To do this, follow these steps:
Add two Button controls to the Form1.vb form.
Note By default, the new buttons are named Button1 and Button2.
In the Properties pane, change the Text property to Play.
In the Properties pane, change the Text property of Button2 to Stop.
Double-click Play, and then add the following code to the Button1_Click method:
Note <C:\Filename.wav> represents the file name of a .wav file.
In Solution Explorer, double-click Form1.vb.
Double-click Stop, and then add the following code to the Button2_Click method:
Run the application. To do this, follow these steps:
On the Debug menu, click Start Debugging.
The sound file plays continuously.
You hear audio output only if your computer has a sound card that is configured correctly. You must also use speakers, earphones, or headphones to hear the audio output.
Note The sound stops playing.
For more information about how to play audio files by using Microsoft Visual Basic .NET or Visual Basic 2005 and the Windows Media Player SDK, click the following article number to view the article in the Microsoft Knowledge Base:
821767 How to play audio files by using Visual Basic .NET or Visual Basic 2005
For more information about the My.Computer.Audio.Play method, visit the following Microsoft Developer Network (MSDN) Web site:
Microsoft Visual Basic 2005, Microsoft Visual Studio 2005 Express Edition, Microsoft Visual Studio 2005 Professional Edition, Microsoft Visual Studio 2005 Standard Edition, Microsoft Visual Studio 2005 Team System Architect Edition, Microsoft Visual Studio 2005 Team System Developer Edition, Microsoft Visual Studio 2005 Team Foundation, Microsoft Visual Studio 2005 Team System Test Edition