HOWTO: Play a Waveform (.WAV) Sound File in Visual BasicLast reviewed: July 3, 1997Article ID: Q86281 |
The information in this article applies to:
THE FOLLOWING SECTION APPLIES TO VISUAL BASIC VERSIONS 4.0 AND 5.0
SUMMARYYou can play a waveform (.wav) sound file from Microsoft Visual Basic for Windows by calling the sndPlaySound API function from the Mmsystem.dll file. In order to be able to call the sndPlaySound API function, you must be using either Microsoft Windows, version 3.1 or the Microsoft Multimedia Extensions for Windows, version 3.0. The following information discusses the sndPlaySound parameters, and includes an example of how to use this function from Visual Basic for Windows.
MORE INFORMATIONTo use the sndPlaySound API from within a Visual Basic for Windows application, you must declare the sndPlaySound function in the global module or in the Declarations section of the Code window. To declare the function, enter this Declare statement:
Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _ (ByVal lpszSoundName As String, ByVal uFlags As Long) As LongHere are explanations for the parameters:
Code SampleThe following code example illustrates how to use the sndPlaySound API function to play a waveform (.wav) sound file. Add the code to the global module or general Declarations section of your form:
Private Declare Function sndPlaySound Lib "WINMM.DLL" Alias _ "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As _ Long) As Long Const SND_SYNC = &H0 Const SND_ASYNC = &H1 Const SND_NODEFAULT = &H2 Const SND_LOOP = &H8 Const SND_NOSTOP = &H10Add the following code to the appropriate Function or Sub procedure in your application:
SoundName$ = "c:\windows\tada.wav" wFlags% = SND_ASYNC Or SND_NODEFAULT x% = sndPlaySound(SoundName$,wFlags%)NOTE: If a large waveform (.wav) sound file is specified and this call fails to play the file in its entirety, you need to adjust the settings on the appropriate sound driver.
THE FOLLOWING SECTION APPLIES TO VISUAL BASIC 3.0 ONLYTo use the sndPlaySound API from within a Visual Basic for Windows application, you must declare the sndPlaySound function in the global module or in the Declarations section of your Code window. To declare the function, enter the following Declare statement as one, single line:
Declare Function sndPlaySound Lib "MMSYSTEM.DLL" (ByVal lpszSoundName As Any, ByVal wFlags%) As IntegerHere are explanations for the parameters:
Code SampleThe following code example illustrates how to use the sndPlaySound API function to play a waveform (.wav) sound file. Add the following code to the global module or general Declarations section of your form:
'VB3Line: Enter the following lines as one line Declare Function sndPlaySound Lib "MMSYSTEM.DLL" (ByVal lpszSoundName$, ByVal wFlags%) As Integer Global Const SND_SYNC = &H0000 Global Const SND_ASYNC = &H0001 Global Const SND_NODEFAULT = &H0002 Global Const SND_LOOP = &H0008 Global Const SND_NOSTOP = &H0010Add the following code to the appropriate Function or Sub procedure in your application:
SoundName$ = "c:\windows\tada.wav" wFlags% = SND_ASYNC Or SND_NODEFAULT x% = sndPlaySound(SoundName$,wFlags%)NOTE: If a large waveform (.wav) sound file is specified and this call fails to play the file in its entirety, you need to adjust the settings on the appropriate sound driver.
REFERENCES"Microsoft Multimedia Development Kit: Programmer's Reference" version 1.0. For more information on adjusting the sound driver settings, query on the following words in the Microsoft Knowledge Base:
Speaker and Sound and Driver and Settings and .WAV and File |
Keywords : APrgOther kbcode vb432 vb4win vb5all vb5howto VBKBWinAPI kbfasttip kbhowto
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |