Results 1 to 6 of 6

Thread: Attaching a sound

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    13

    Attaching a sound

    Hi all could someone teach me how to attach a sound clip (wav) to my vb6 program? its like after i click this button i want it to play a specific audio file

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Attaching a sound

    Welcome to the forums.

    Is this what you're looking for?
    VB Code:
    1. Private Const SND_APPLICATION = &H80         ' look for application specific association
    2. Private Const SND_ALIAS = &H10000     ' name is a WIN.INI [sounds] entry
    3. Private Const SND_ALIAS_ID = &H110000    ' name is a WIN.INI [sounds] entry identifier
    4. Private Const SND_ASYNC = &H1         ' play asynchronously
    5. Private Const SND_FILENAME = &H20000     ' name is a file name
    6. Private Const SND_LOOP = &H8         ' loop the sound until next sndPlaySound
    7. Private Const SND_MEMORY = &H4         ' lpszSoundName points to a memory file
    8. Private Const SND_NODEFAULT = &H2         ' silence not default, if sound not found
    9. Private Const SND_NOSTOP = &H10        ' don't stop any currently playing sound
    10. Private Const SND_NOWAIT = &H2000      ' don't wait if the driver is busy
    11. Private Const SND_PURGE = &H40               ' purge non-static events for task
    12. Private Const SND_RESOURCE = &H40004     ' name is a resource name or atom
    13. Private Const SND_SYNC = &H0         ' play synchronously (default)
    14. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    15. Private Sub Form_Load()
    16.     'KPD-Team 2000
    17.     'URL: [url]http://www.allapi.net/[/url]
    18.     'E-Mail: [email][email protected][/email]
    19.     PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC
    20. End Sub
    This world is not my home. I'm just passing through.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    13

    Re: Attaching a sound

    there seems to be something wrong with this line :

    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

    There was a pop up error msg...


  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Attaching a sound

    This keeps repeating until you press the button again to stop it.
    Add a command button, and erase everything in the form, before you paste this code in. (Make sure that your wave file is in the right folder)

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const SND_APPLICATION = &H80         ' look for application specific association
    4. Private Const SND_ALIAS = &H10000     ' name is a WIN.INI [sounds] entry
    5. Private Const SND_ALIAS_ID = &H110000    ' name is a WIN.INI [sounds] entry identifier
    6. Private Const SND_ASYNC = &H1         ' play asynchronously
    7. Private Const SND_FILENAME = &H20000     ' name is a file name
    8. Private Const SND_LOOP = &H8         ' loop the sound until next sndPlaySound
    9. Private Const SND_MEMORY = &H4         ' lpszSoundName points to a memory file
    10. Private Const SND_NODEFAULT = &H2         ' silence not default, if sound not found
    11. Private Const SND_NOSTOP = &H10        ' don't stop any currently playing sound
    12. Private Const SND_NOWAIT = &H2000      ' don't wait if the driver is busy
    13. Private Const SND_PURGE = &H40               ' purge non-static events for task
    14. Private Const SND_RESOURCE = &H40004     ' name is a resource name or atom
    15. Private Const SND_SYNC = &H0         ' play synchronously (default)
    16. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    17. Dim flag As Boolean
    18.  
    19. Private Sub Command1_Click()
    20. If Not flag Then
    21.   Command1.Caption = "Stop"
    22.   PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_ASYNC Or SND_LOOP
    23. Else
    24.   Command1.Caption = "Play"
    25.   PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_MEMORY
    26. End If
    27. flag = Not flag
    28. End Sub
    29.  
    30. Private Sub Form_Load()
    31.     'KPD-Team 2000
    32.     'URL: [url]http://www.allapi.net/[/url]
    33.     'E-Mail: [email][email protected][/email]
    34.  Command1.Caption = "Play"
    35. End Sub

  5. #5
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Attaching a sound

    there seems to be something wrong with this line :

    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

    There was a pop up error msg...
    Start a new project. Paste in the code I gave you. Do you still get the message?
    This world is not my home. I'm just passing through.

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Posts
    13

    Re: Attaching a sound

    Oh Great its working already, thanks alot guys

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