Not a Member Yet,
Click here to Register

ID: 401
Viewed: 3352
Added: Aug 19, 2002
Version:
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

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.

Highlight all by clicking in box
<!---Declaration--->
Declarations

'Add the following code to the declarations section:

Declare Function sndPlaySound Lib "winmm" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Public Const SND_SYNC = &H0 ' play synchronously (default)
Public Const SND_ASYNC = &H1 ' play asynchronously
Public Const SND_LOOP = &H8 ' loop the sound until next


Highlight All
<!---Code--->
'Now, go into the form design view and add a command button 'to the form. Add the following code into the 'Command1_Click event:

Call sndPlaySound(ByVal "c:windowsmediaThe Microsoft Sound.wav", SND_ASYNC)

'(Of course, feel free to substitute any available .wav 'file into this code)
;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 snippetlibrary.com All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!