CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Location
    Quebec, Canada
    Posts
    4

    Playing Audio Files

    How do you can you simply play audio files (ie .wav) when a command is clicked?

    Thanks in advance.

    yellowTIGER


  2. #2
    Join Date
    Jul 2000
    Location
    The Netherlands
    Posts
    26

    How to play a WAV file

    put this code in a module (or replace public with private and place anywhere...):

    public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (byval lpszSoundName as string, byval uFlags as Long) as Long

    public Const SND_ASYNC = &H1
    public Const SND_LOOP = &H8
    public Const SND_MEMORY = &H4
    public Const SND_NODEFAULT = &H2
    public Const SND_SYNC = &H0



    This is all the declaration you need to play a .wav file. Use code of this sort to play a file called "C:\test.wav" when command1 is clicked:

    private Sub Command1_Click()
    sndPlaySound "C:\test.wav", SND_ASYNC
    End Sub



    This will play the sound and immediately continue to execute code. If you put the flag SND_SYNC instead of SND_ASYNC, code execution will stop until the sound has finished playing (be careful with this one; is you put this kind of sound in a loop, you may hang your system!!!). It's fast and easy. I hope this info was useful!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured