Technology Programming

How to Play Sounds With Visual Basic

    • 1). Open your Visual Basic compiler and access your project. Create a new procedure by typing in the "Sub" command, such as "Sub PlayMusic()" if you want the procedure to be named "PlayMusic."

    • 2). Scroll down a few lines and type in the ending "End Sub" command to let the compiler know where the procedure ends. Move your cursor back up anywhere in between the "Sub PlayMusic()" and "End Sub" commands.

    • 3). Use the "My.Computer.Audio.Play" method to play a sound file saved on the computer. For example type "My.Computer.Audio.Play("C:\MySound.wav", AudioPlayMode.Background)" if you want to play the file named "MySound.wav" located on the C drive.

    • 4). Change the final argument of the method to "AudioPlayMode.BackgroundLoop" if you want the sound to start over again once it ends. For example type "My.Computer.Audio.Play("C:\MySound.wav", AudioPlayMode.BackgroundLoop)" to continuously play the "MySound.wav" file.



Leave a reply