Microsoft KB Archive/914353

= How to play .wav sound files and system sounds by using the My namespace in Visual Basic 2005 =

Article ID: 914353

Article Last Modified on 12/6/2006

-

APPLIES TO


 * 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

-





SUMMARY
''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.''



INTRODUCTION
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



MORE INFORMATION
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. </li> 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.</li> Click Button1.</li> In the Properties pane, change the Text property to Play .</li> Click Button2.</li> In the Properties pane, change the Text property of Button2 to Stop .</li></ol> </li>  Double-click Play, and then add the following code to the Button1_Click method: My.Computer.Audio.Play(&quot;<C:\Filename.wav>&quot;, AudioPlayMode.BackgroundLoop) Note  represents the file name of a .wav file. </li> In Solution Explorer, double-click Form1.vb.</li>  Double-click Stop, and then add the following code to the Button2_Click method: My.Computer.Audio.Stop </li> Run the application. To do this, follow these steps:  On the Debug menu, click Start Debugging.</li> Click Play.

Notes <ul> The sound file plays continuously.</li> 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.</li></ul> </li> <li>Click Stop.

Note The sound stops playing.</li></ol> </li></ol>

<div class="references_section">