Visual Basic / Sound / Sound Player
Snippet details
ID: 401
Viewed: 1227
Added: 2002-08-19
Version:
Multimedia in VB
Dateline: 04/08/99
Introduction
It is a rare application now that doesn't feature some kind of sound effect - be it an simple alarm beep signifying a calendar event in Outlook 98, or the CD quality background music for the 3D games of today. This article will show you how to add sound into your application, with only one line of code!
In the beginning . . . there was Beep()
Of course, the easiest way to make your application a bit more noisy is with the trusty "Beep" command. On using this code, a standard system sound is heard through the default sound device. If you are looking for a very easy way to attract attention to your program, beep is the answer. However, if you are looking to play some more interesting sounds...
Enter Winmm.dll
Deep within the Windows system directory lies a Dynamic Link Library that contains functions to control virtually all of the Windows sound devices. Using the API, you can take advantage of this DLL to play wav files with just one line of code.
Of course, if you are a little API shy, you may be interested to know that Visual Basic features a multimedia (MCI) control that encapsulates all the important functions into one basic ActiveX. But why use this control when you can call the API directly, and avoid the necessary overheads of using controls?
Let's create a simple application that plays the Microsoft Sound when a command button is pressed.
First, start up Visual Basic and start a new project. Add a module to the project, and open it up in the code window. Let's create a simple application that plays the Microsoft Sound when a command button is pressed.
First, start up Visual Basic and start a new project. Add a module to the project, and open it up in the code window.
Now, run your program, and click the command button. Voila! You have just created a multimedia application!
Hang on a minute... It doesn't work! If the code does not work, please check the following points:
Does the sound file you have used in the code actually exist?
Have you turned on the speakers and turned up the sound volume on your system?
Does your system support wave sounds?
Have you included the correct declarations in a module?
If all else fails your system may not support sound effects.
Conclusion
You have just learned how with only one line of code you can create a fully working sound player.
Dateline: 04/08/99
Introduction
It is a rare application now that doesn't feature some kind of sound effect - be it an simple alarm beep signifying a calendar event in Outlook 98, or the CD quality background music for the 3D games of today. This article will show you how to add sound into your application, with only one line of code!
In the beginning . . . there was Beep()
Of course, the easiest way to make your application a bit more noisy is with the trusty "Beep" command. On using this code, a standard system sound is heard through the default sound device. If you are looking for a very easy way to attract attention to your program, beep is the answer. However, if you are looking to play some more interesting sounds...
Enter Winmm.dll
Deep within the Windows system directory lies a Dynamic Link Library that contains functions to control virtually all of the Windows sound devices. Using the API, you can take advantage of this DLL to play wav files with just one line of code.
Of course, if you are a little API shy, you may be interested to know that Visual Basic features a multimedia (MCI) control that encapsulates all the important functions into one basic ActiveX. But why use this control when you can call the API directly, and avoid the necessary overheads of using controls?
Let's create a simple application that plays the Microsoft Sound when a command button is pressed.
First, start up Visual Basic and start a new project. Add a module to the project, and open it up in the code window. Let's create a simple application that plays the Microsoft Sound when a command button is pressed.
First, start up Visual Basic and start a new project. Add a module to the project, and open it up in the code window.
Now, run your program, and click the command button. Voila! You have just created a multimedia application!
Hang on a minute... It doesn't work! If the code does not work, please check the following points:
Does the sound file you have used in the code actually exist?
Have you turned on the speakers and turned up the sound volume on your system?
Does your system support wave sounds?
Have you included the correct declarations in a module?
If all else fails your system may not support sound effects.
Conclusion
You have just learned how with only one line of code you can create a fully working sound player.
General Details
Snippet uploaded by: snippet
Email : webmaster@snippetlibrary.com
Snippet By: Unknown
| Snippet By: | Unknown |
| Declarations | |
| Code | |
| Highlight All | |
No Reviews to show
