Results 1 to 11 of 11

Thread: Play Sound

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Location
    Maine
    Posts
    20

    Play Sound

    How Do You Get Your Project To Play A Sound.... For Instance Lets Say I Did This

    Code:
    Private Sub Form_MouseUp(Button As Integer, Shift As Integer)
    'I Want The Sound To Play Here
    End Sub


    thanks in advanced

  2. #2
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860

    well

    theres always the multimedia control (add-ins) or u can use directX, which i have no idea how to.
    Don't pay attention to this signature, it's contradictory.

  3. #3
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Try something like this:

    VB Code:
    1. Option Explicit
    2. 'API Declarations
    3. #If Win32 Then '32-Bit windows
    4.     Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
    5.         (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long 'The API that lets sound be played
    6. #Else 'Other Windows
    7.     Public Declare Function sndPlaySound Lib "MMSYSTEM.DLL" _
    8.         (ByVal lpszSoundName As Any, ByVal wFlags As Integer) As Integer 'The API that lets sound be played
    9. #End If
    10. 'API Constants Used for flags in Play Sound function
    11. Public Enum SoundFlags
    12.     SND_LOOP = &H8 ' Loop the sound until next sndPlaySound
    13.     SND_ALIAS = &H10000 ' Name is a WIN.INI [sounds] entry
    14.     SND_ALIAS_ID = &H110000 ' Name is a WIN.INI [sounds] entry identifier
    15.     SND_ALIAS_START = 0 ' Must be > 4096 to keep strings in same section of resource file
    16.     SND_APPLICATION = &H80 ' Look for application specific association
    17.     SND_ASYNC = &H1 ' Play asynchronously
    18.     SND_FILENAME = &H20000 ' Name is a file name
    19.     SND_MEMORY = &H4 ' lpszSoundName points to a memory file
    20.     SND_NODEFAULT = &H2 ' Silence not default, if sound not found
    21.     SND_NOSTOP = &H10 ' Don't stop any currently playing sound
    22.     SND_NOWAIT = &H2000 ' Don't wait if the driver is busy
    23.     SND_PURGE = &H40 ' Purge non-static events for task
    24.     SND_RESERVED = &HFF000000 ' In particular these flags are reserved
    25.     SND_RESOURCE = &H40004 ' Name is a resource name or atom
    26.     SND_SYNC = &H0 ' Play synchronously (default)
    27.     SND_TYPE_MASK = &H170007
    28.     SND_VALID = &H1F ' Valid flags          / ;Internal /
    29.     SND_VALIDFLAGS = &H17201F ' Set of valid flag bits.  Anything outside
    30. End Enum
    31.  
    32. Private Sub PlaySound(ByVal FileName As String, _
    33.     Optional Flags As SoundFlags = SND_FILENAME Or SND_NOSTOP)
    34.    
    35.     On Error Resume Next 'Goto next line on an error
    36.  
    37.     'If the filename is not "" then play the sound
    38.     If FileName <> "" Then Call sndPlaySound(FileName, Flags)
    39. End Sub

  4. #4
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80
    I got it to play sound... but it stops everything in the program until it is done playing... What fixes that?

  5. #5
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    I haven't done this for years and I believe I did it a different way but if you look at the flags setting it to asynchronus should work...
    Can't say for sure I always use DirectSound
    Sanity is a full time job

    Puh das war harter Stoff!

  6. #6
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80
    I think I've tried that, but I'm not sure I've done it right.

    PlaySound ("filename"), (SND_SYNC)

    Is that right? If so, it still freezes while it plays a sound.

  7. #7
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Use the SND_ASYNC (Asynchronous) flag to allow execution while the sound plays.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  8. #8
    Lively Member
    Join Date
    Sep 2001
    Location
    2 miles from everywhere
    Posts
    80
    Hmm... it works now.. even though I already tried it and it didnt Oh well...

  9. #9
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Yeah sorry about that, the default flags should have had "Or SND_ASYNC" there too.

  10. #10

    Smile

    hi,
    can you see the Attach file the example make your soulve it.
    Attached Files Attached Files

  11. #11
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I couldn't be bothered to put my speakers on to test it, but do you need to specify the absolute path, not just "sound_1.wav"? Something like App.Path & "\Sound_1.wav". I've never use the multimedia control, so I'm not sure.

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