Results 1 to 4 of 4

Thread: Throw the timers away

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87

    Unhappy

    I had it already about this in this thread http://forums.vb-world.net/showthrea...threadid=33198 but after trying everything and more with timers I found out timers aren't the best way to play a wav file with exactly the same time between each 'beat'.
    Does somebody another way than using the timer to do this more exactly. (a module or something)

  2. #2
    Guest
    How about this code?

    Code:
    Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
    (ByVal lpszName As String, ByVal hModule As Long, ByVal _
    dwFlags As Long) As Long
    
    Sub Playsoundx(sndName as String)
        Playsound sndName, vbNull, &H20000 Or &H8 Or &H1
    End Sub
    
    Sub EndSoundx()
        PlaySound vbNull, vbNull, &H20000 Or &H8
    End Sub
    Usage:

    Code:
        PlaySoundx "Filename"   'It will loop until you call EndSoundx.
        EndSoundx               'Ends the Sound
    Aaron Young is old-fashioned, so he likes to use the sndPlaySound.

  3. #3
    Guest
    Aaron Young is not "old-fashioned". In my opinion, he is one of the best people on this forum.

    If you want to omit the Timer, simply create your own using GetTickCount.
    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 Declare Function GetTickCount Lib "kernel32" () As Long
    Dim bTime As Boolean
    
    Sub TimerEx(Interval As Long)
    
        Do While bTime = True
            start = GetTickCount
            
            Do While GetTickCount < start + Interval
            DoEvents '<--You can remove this line if you don't want the system to do tasks
            Loop
            
            PlaySound "MyFile.wav", 0&, &H1
        Loop
        
    End Sub
    
    
    Private Sub Command1_Click()
        'Start playing the sound at intervals of 1 second
        bTime = True
        TimerEx 1000
    End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    87

    Question Another problem

    What should I do if the time between two beats need to be shorter than the length of the wav file? This means that I have to play two sounds at the same moment because I don't want the previous beat to be stopped in the middle.

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