Results 1 to 7 of 7

Thread: PlaySound API

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2006
    Location
    Paris
    Posts
    301

    Arrow PlaySound API

    Hi,
    My motherboard seems not to be compatible with the api Beep because I can't hear a sound,while it worked with my old PC.
    So I'm trying to figure out how to use playsound but the first parameter is a
    string and I don't have a clue on what to use for that string.
    I just need to play simple beeps that reproduce basic music tones (a,b,c...)
    Thanks for your help.
    Horazio.

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: PlaySound API

    vb Code:
    1. Option Explicit
    2.  
    3. 'This code uses the Playsound API function. Playsound can read files from standard WAV files on
    4. 'disk, by reference from the system registry, or from a resource file. For the application
    5. 'developer, this means that you can create a registry entry for your sound effects, which means
    6. 'that the end user can use the control panel to customize their preferences in sounds. You avoid
    7. 'designing another configuration screen or panel, and the user can still customize the application.
    8.  
    9. 'lpszName points to a registry entry
    10. 'Do not use SND_RESOURSE or SND_FILENAME
    11. Private Const SND_ALIAS& = &H10000
    12. 'Playsound returns immediately
    13. 'Do not use SND_SYNC
    14. Private Const SND_ASYNC& = &H1
    15. 'The name of a wave file.
    16. 'Do not use with SND_RESOURCE or SND_ALIAS
    17. Private Const SND_FILENAME& = &H20000
    18. 'Unless used, the default beep will
    19. 'play if the specified resource is missing
    20. Private Const SND_NODEFAULT& = &H2
    21. 'Fail the call & do not wait for
    22. 'a sound device if it is otherwise unavailable
    23. Private Const SND_NOWAIT& = &H2000
    24. 'Use a resource file as the source.
    25. 'Do not use with SND_ALIAS or SND_FILENAME
    26. Private Const SND_RESOURCE& = &H40004
    27. 'Playsound will not return until the
    28. 'specified sound has played.  Do not
    29. 'use with SND_ASYNC
    30. Private Const SND_SYNC& = &H0
    31. Public Enum enSound_Source
    32.     ssFile = SND_FILENAME&
    33.     ssRegistry = SND_ALIAS&
    34. End Enum
    35. 'These are common sounds available from the registry
    36. Public Const elDefault = ".Default"
    37. Public Const elGPF = "AppGPFault"
    38. Public Const elClose = "Close"
    39. Public Const elEmptyRecycleBin = "EmptyRecycleBin"
    40. Public Const elMailBeep = "MailBeep"
    41. Public Const elMaximize = "Maximize"
    42. Public Const elMenuCommand = "MenuCommand"
    43. Public Const elMenuPopUp = "MenuPopup"
    44. Public Const elMinimize = "Minimize"
    45. Public Const elOpen = "Open"
    46. Public Const elRestoreDown = "RestoreDown"
    47. Public Const elRestoreUp = "RestoreUp"
    48. Public Const elSystemAsterisk = "SystemAsterisk"
    49. Public Const elSystemExclaimation = "SystemExclaimation"
    50. Public Const elSystemExit = "SystemExit"
    51. Public Const elSystemHand = "SystemHand"
    52. Public Const elSystemQuestion = "SystemQuestion"
    53. Public Const elSystemStart = "SystemStart"
    54. Private Declare Function PlaySound& Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long)
    55. 'hModule is only used if SND_RESOURCE& is set and represents
    56. 'an HINSTANCE handle.  This example doesn't support playing
    57. 'from a resource file.
    58.  
    59. 'Plays sounds from the registry or a disk file
    60. 'Doesn't care if the file is missing
    61. Public Function EZPlay(ssname As String, sound_source As enSound_Source) As Boolean
    62.     If PlaySound(ssname, 0&, sound_source + SND_ASYNC + SND_NODEFAULT) Then
    63.         EZPlay = True
    64.     Else
    65.         EZPlay = False
    66.     End If
    67. End Function
    68.  
    69. 'How to call this function
    70. 'Call EZPlay("C:\WINDOWS\media\chimes.wav",ssFile)
    CS

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2006
    Location
    Paris
    Posts
    301

    Re: PlaySound API

    Thanks for your help but this is way too much complicated.
    If I understood right, PlaySound reads a WAV file.
    I just need something that "beeps" simple sounds....the problem is that the API Beep does not work for some strange reason.
    I'm afraid it's the motherboard.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: PlaySound API

    If the inability to play the sound that you want is hardware related, then nothing is going to work unless the hardware problem is addressed.

    Have you tried the BEEP API on different machines?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2006
    Location
    Paris
    Posts
    301

    Re: PlaySound API

    It's kinda strange.
    Standard BEEP works,while API Beep does not....
    It's hardware related. I'm 100% sure

  6. #6
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: PlaySound API

    Take a look at http://www.vbforums.com/showthread.php?t=436758. Post 35 has a test prog that uses several methods of calling the playsound APIs you can try.

  7. #7
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: PlaySound API

    Quote Originally Posted by horazio
    It's kinda strange.
    Standard BEEP works,while API Beep does not....
    It's hardware related. I'm 100% sure
    Thats the same for me, always has been.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

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