Results 1 to 4 of 4

Thread: Playing Wave Files

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    9

    Question

    If I have an alarm clock and when the alarm goes off at a specified time, I use the Beep function. How do I change the code to play a wave file instead of Beep function? Is there a simple way?

  2. #2
    Guest
    Use the PlaySound API.
    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()
    
        'Play the WAV
        PlaySound "C:\MyFile.wav", 0&, &H1
    
    End Sub

  3. #3
    Guest
    If Megatron's code doesn't work, you could also use:

    Code:
    Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Global Const SND_ASYNC = &H1
    Global Const SND_NODEFAULT = &H2
    
    Sub Playwav(file)
    SoundName$ = file
    wFlags% = SND_ASYNC Or SND_NODEFAULT
    X% = sndPlaySound(SoundName$, wFlags%): NoFreeze% = DoEvents()
    End Sub
    
    Usage:
    'Play
    'Playwav "C:\wavfile.wav"
    'Stop
    'Playwav " "

  4. #4
    Guest
    Keep in mind that sndPlaySound is superseded by PlaySound, hence it's obsolete.

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