08-07-2024, 05:36 PM
I haven't tested this code, but wouldn't something like this work?
And then you just replace the `_SndPlayCopy` calls with `PlaySound` calls and call `KillSounds` when you're done. It's not super pretty but it doesn't seem all that bad overall.
Code: (Select All)
ReDim HandleCache(20) As Long
Sub PlaySound (handle As Long)
For i = 1 to UBOUND(HandleCache)
If HandleCache(i) <= 0 _OrElse Not _SndPlaying(HandleCache(i)) Then
_SndClose HandleCache(i)
HandleCache(i) = _SndCopy(handle)
_SndPlay HandleCache(i)
Exit Sub
End If
Next
ReDim HandleCache(UBOUND(HandleCache + 1)) As Long
HandleCache(UBOUND(HandleCache)) = _SndCopy(handle)
_SndPlay HandleCache(UBOUND(HandleCache))
End Sub
Sub KillSounds ()
For i = 1 to Ubound(HandleCache)
If HandleCache(i) > 0 Then
_SndClose HandleCache(i)
HandleCache(i) = -1
End If
Next
End Sub
And then you just replace the `_SndPlayCopy` calls with `PlaySound` calls and call `KillSounds` when you're done. It's not super pretty but it doesn't seem all that bad overall.