Play a .wav without MCI control.......sndPlaySound ?? 
Author Message
 Play a .wav without MCI control.......sndPlaySound ??

Hi all,

Does any one know how I can play a sound file without using the MCI
control??

This is all I need to do, and I'm sure including this control in my app is a
little 'overkill', as well as it using quite a lot of resources for one
measly wave :-)

I know there's an API out there, sndPlaySound....

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

...but I'm a little unsure how to implement this, as these API calls are
fairly new to me :-(

I'd really appreciate you help...

Many thanks

John



Mon, 30 Jul 2001 03:00:00 GMT  
 Play a .wav without MCI control.......sndPlaySound ??

Hi all.

Just got it to work......

If anyone else was looking for this....here's your answer

Cheers :-)

HOWTO: Play a Waveform (.WAV) Sound File in Visual Basic
            Last reviewed: July 3, 1997
            Article ID: Q86281  
            The information in this article applies to:
                a.. Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
                b.. Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 32-bit only, for Windows, version 4.0
                c.. Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0
                d.. Microsoft Visual Basic for Windows, version 1.0

            THE FOLLOWING SECTION APPLIES TO VISUAL BASIC VERSIONS 4.0 AND 5.0

            SUMMARY
            You 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 INFORMATION
            To 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 Long
            Here are explanations for the parameters:
                a.. lpszSoundName specifies the name of the sound to play. The function first searches the [sounds] section of the Win.ini file for an entry with the specified name, and then plays the associated waveform sound file. If no entry by this name exists, it is assumed the specified name is the name of a waveform sound file. If this parameter is null, any currently playing sound is stopped. Use 0& to provide a null value.
                b.. uFlags specifies options for playing the sound using one or more of the following flags:

    - SND_SYNC specifies that the sound is played synchronously and the
      function does not return until the sound ends.

    - SND_ASYNC specifies that the sound is played asynchronously and the
      function returns immediately after beginning the sound.

    - SND_NODEFAULT specifies that if the sound cannot be found, the
      function returns silently without playing the default sound.

    - SND_LOOP specifies that the sound will continue to play continuously
      until sndPlaySound is called again with the lpszSoundName$ parameter
      set to null. You must also specify the SND_ASYNC flag to loop sounds.

    - SND_NOSTOP specifies that if a sound is currently playing, the
      function will immediately return False without playing the requested
      sound.

            The sndPlaySound function returns True (-1) if the sound is played, otherwise it returns False (0).

            Code Sample
            The 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 = &H10
            Add 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 ONLY
            To 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 Integer
            Here are explanations for the parameters:
                a.. lpszSoundName specifies the name of the sound to play. The function first searches the [sounds] section of the Win.ini file for an entry with the specified name, and then plays the associated waveform sound file. If no entry by this name exists, it is assumed the specified name is the name of a waveform sound file. If this parameter is null, any currently playing sound is stopped. Use 0& to provide a null value.
                b.. uFlags specifies options for playing the sound using one or more of the following flags:

    - SND_SYNC specifies that the sound is played synchronously and the
      function does not return until the sound ends.

    - SND_ASYNC specifies that the sound is played asynchronously and the
      function returns immediately after beginning the sound.

    - SND_NODEFAULT specifies that if the sound cannot be found, the
      function returns silently without playing the default sound.

    - SND_LOOP specifies that the sound will continue to play continuously
      until sndPlaySound is called again with the lpszSoundName$ parameter
      set to null. You must also specify the SND_ASYNC flag to loop sounds.

    - SND_NOSTOP specifies that if a sound is currently playing, the
      function will immediately return False without playing the requested
      sound.

            The sndPlaySound function returns True (-1) if the sound is played, otherwise it returns False (0).

            Code Sample
            The 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    = &H0010
            Add 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
                Version : 1.0 2.0 3.0 4.0 5.0
                Platform : WINDOWS

            Last reviewed: July 3, 1997
            ? 1998 Microsoft Corporation. All rights reserved. Terms of Use.



Mon, 30 Jul 2001 03:00:00 GMT  
 Play a .wav without MCI control.......sndPlaySound ??

Hi all.

Just got it to work......

If anyone else was looking for this....here's your answer

Cheers :-)

HOWTO: Play a Waveform (.WAV) Sound File in Visual Basic
            Last reviewed: July 3, 1997
            Article ID: Q86281  
            The information in this article applies to:
                a.. Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
                b.. Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 32-bit only, for Windows, version 4.0
                c.. Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0
                d.. Microsoft Visual Basic for Windows, version 1.0

            THE FOLLOWING SECTION APPLIES TO VISUAL BASIC VERSIONS 4.0 AND 5.0

            SUMMARY
            You 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 INFORMATION
            To 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 Long
            Here are explanations for the parameters:
                a.. lpszSoundName specifies the name of the sound to play. The function first searches the [sounds] section of the Win.ini file for an entry with the specified name, and then plays the associated waveform sound file. If no entry by this name exists, it is assumed the specified name is the name of a waveform sound file. If this parameter is null, any currently playing sound is stopped. Use 0& to provide a null value.
                b.. uFlags specifies options for playing the sound using one or more of the following flags:

    - SND_SYNC specifies that the sound is played synchronously and the
      function does not return until the sound ends.

    - SND_ASYNC specifies that the sound is played asynchronously and the
      function returns immediately after beginning the sound.

    - SND_NODEFAULT specifies that if the sound cannot be found, the
      function returns silently without playing the default sound.

    - SND_LOOP specifies that the sound will continue to play continuously
      until sndPlaySound is called again with the lpszSoundName$ parameter
      set to null. You must also specify the SND_ASYNC flag to loop sounds.

    - SND_NOSTOP specifies that if a sound is currently playing, the
      function will immediately return False without playing the requested
      sound.

            The sndPlaySound function returns True (-1) if the sound is played, otherwise it returns False (0).

            Code Sample
            The 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 = &H10
            Add 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 ONLY
            To 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 Integer
            Here are explanations for the parameters:
                a.. lpszSoundName specifies the name of the sound to play. The function first searches the [sounds] section of the Win.ini file for an entry with the specified name, and then plays the associated waveform sound file. If no entry by this name exists, it is assumed the specified name is the name of a waveform sound file. If this parameter is null, any currently playing sound is stopped. Use 0& to provide a null value.
                b.. uFlags specifies options for playing the sound using one or more of the following flags:

    - SND_SYNC specifies that the sound is played synchronously and the
      function does not return until the sound ends.

    - SND_ASYNC specifies that the sound is played asynchronously and the
      function returns immediately after beginning the sound.

    - SND_NODEFAULT specifies that if the sound cannot be found, the
      function returns silently without playing the default sound.

    - SND_LOOP specifies that the sound will continue to play continuously
      until sndPlaySound is called again with the lpszSoundName$ parameter
      set to null. You must also specify the SND_ASYNC flag to loop sounds.

    - SND_NOSTOP specifies that if a sound is currently playing, the
      function will immediately return False without playing the requested
      sound.

            The sndPlaySound function returns True (-1) if the sound is played, otherwise it returns False (0).

            Code Sample
            The 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    = &H0010
            Add 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
                Version : 1.0 2.0 3.0 4.0 5.0
                Platform : WINDOWS

            Last reviewed: July 3, 1997
            ? 1998 Microsoft Corporation. All rights reserved. Terms of Use.



Mon, 30 Jul 2001 03:00:00 GMT  
 Play a .wav without MCI control.......sndPlaySound ??
Hi all....

Sussed it.....MSDN article Q86281

Thanks anyway :-)



Mon, 30 Jul 2001 03:00:00 GMT  
 Play a .wav without MCI control.......sndPlaySound ??


Fri, 19 Jun 1992 00:00:00 GMT  
 Play a .wav without MCI control.......sndPlaySound ??
Sorry about all those posts.......my server was acting a bit strange !!!


Mon, 30 Jul 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Play .wav in VB4-32bit without MCI control

2. Q: using MCI control to play .wav file in a command button

3. Using sndPlaySound to play .WAV from memory in VB

4. Q: Playing MIDI-files without MCI control

5. How to play and control a MIDI file without MCI OCX

6. Is there any way to play a wav and avi without having teh ocx multimedia controls

7. Play Wav Files without Custom Controls ???

8. MCI and playing *.wav files?

9. Playing WAV files with MCI.MMControl

10. Play MIDI without MCI!

11. playing sounds without using MCI

12. How best to play a WAV file at a variable volume without affecting system volume

 

 
Powered by phpBB® Forum Software