Results 1 to 4 of 4

Thread: Playing sounds in VB5

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    United Kingdom
    Posts
    1

    Post

    Hi,
    I wish to draw a click event control on the form and when pressed will play a wave file.
    Can anyone help me with the code behind the button -- or whatever.
    For information I am using VB5 (Professioonal) Edition is that helps !!!

    Regards
    Bernie

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

    Post

    Hey Bernie

    You mean a command button...?

    Use API. Try this:

    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

    Private Sub StopSound_Click()
    Dim i As Long, RS As String, cb As Long
    RS = Space$(128)
    i = mciSendString("stop sound", RS, 128, cb)
    i = mciSendString("close sound", RS, 128, cb)
    End Sub

    Private Sub StartSound_Click()
    StopSound_Click
    Dim i As Long, RS As String, cb As Long, W$
    RS = Space$(128)
    W$ = "c:\windows\media\done.wav"
    i = mciSendString("open waveaudio!" & W$ & " alias sound", RS, 128, cb)
    If i Then MsgBox "Error! Probably file not found. Modify the code to point to a .WAV file on your system."
    i = mciSendString("play sound", RS, 128, cb)
    End Sub

    Good luck

    Regards,

    ------------------
    - Chris
    [email protected]
    If it ain't broke - don't fix it

  3. #3
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    Post

    In the module, or the general declarations:

    Private Const SND_ASYNC = &H1
    Private Const SND_NODEFAULT = &H2
    Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

    (if you put it in the general declarations, only that form can use it, and you have to put the word Private in front of Declare)

    In the form_click event, put this:

    Call sndPlaySound("file name", SND_ASYNC AND SND_NODEFAULT)

    This will play the sound with no default ding or anything if it doesn't find the file, and it will suspend execution until the file is done. To let the program keep running, delete the SND_ASYNC part.

    good luck,

    bob

    P.S. My way's easier.

    [This message has been edited by Bob Baddeley (edited 01-29-2000).]

  4. #4
    New Member
    Join Date
    Aug 1999
    Posts
    15

    Post

    hehe, now we know that is an ad.

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