Results 1 to 8 of 8

Thread: sounds

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    37
    When I add a sound to my program, the user can't click on any buttons until the sound is finished playing. How can I have a background sound and still be able to click on buttons and stuff at the same time?

  2. #2
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Exclamation Code?

    What code do you use for playing that sound?

    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  3. #3
    Guest
    After the code you use to play the sound, put a DoEvents in there, and that should enable you to do anything else while the sound is playing. Although, you shouldn't have this problem.

    Use the PlaySound api function.

    Code:
    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    
    Private Sub Command1_Click()
    
        PlaySound "C:\MyFile.wav", 0&, &H1
        DoEvents
    
    End Sub

  4. #4
    Guest
    Well, Escaflowne here, and you can try:

    Code:
    Public Declare Function PlaySd Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    
    Public Sub SoundPlay (Filename as String)
    
        PlaySd (Filename, vbNull, &H1 Or &H20000)
    
    End Sub
    
    Public Sub StopSound ()
    
        PlaySd ("",vbNull, &H1 Or &H20000)
    
    End Sub
    Usage:
    Code:
    'Start Sound:
    SoundPlay [Filename]
    'Stop Sound:
    StopSound

  5. #5
    Guest
    Well, Matt of Microsoft, you don't need the "DoEvents" because when &H1 is the last parameter, it already will allow execution.

  6. #6
    Guest
    Escaflowne is correct, Matthew. In your example, you played the sound asynchronously which means the function will return directly after the function was called.

    I think, however, that you were referring to playing it synchronously, in which case (logically speaking) it would not work because it does not return until the sound has finished.

  7. #7
    Guest
    No, Megatron, that's not what I mean .

    When the last valus is &H1, it is already ASYNC, so the doevents will only slow the program down, so the doevents is not needed.

    Oh, and for full compatibility, add " Or &H20000" for "FileName Processing", which means that the first parameter is a filename.

  8. #8
    Guest
    Not really. If you play it asynchronously, it will be slowed down anyway hence DoEvents is simply not needed.

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