Sound abspielen
Sounddateien können einmalig oder dauernd abgespielt
werden (asynchron oder auch synchron), das Abspielen kann gestoppt und die Lautstärke
eingestellt werden.
Beispieldatei (sound.zip 21 kB)
Private Declare Function sndPlaySound Lib "winmm.dll"
_
Alias "sndPlaySoundA" (ByVal lpszSoundName
As String, _
ByVal uFlags As Long) As Long
Private Declare Function waveOutSetVolume Lib "winmm.dll"
_
(ByVal uDeviceID As Long, ByVal dwVolume As
Long) As Long
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_LOOP = &H8
Const SND_PURGE = &H40
Public Sub SoundPlayAsyncOnce(Sound As String)
'SND_SYNC für synchrones Abspielen.
sndPlaySound Sound, SND_ASYNC
End Sub
Public Sub SoundPlayAsyncLoop(Sound As String)
'SND_SYNC für synchrones Abspielen.
sndPlaySound Sound, SND_ASYNC Or SND_LOOP
End Sub
Public Sub SoundStop()
sndPlaySound 0, SND_PURGE
End Sub
Sub TestLautstärke()
Dim Links As Integer, Rechts As Integer
Links = 25 '%
Rechts = 25 '%
SoundVolume Links, Rechts
End Sub
Public Sub SoundVolume(ProzentLinks As Integer, _
ProzentRechts As Integer)
Dim Links As Long, Rechts As Long, Lautstärke As Long
If ProzentLinks > 100 Then ProzentLinks = 100
If ProzentRechts > 100 Then ProzentRechts = 100
If ProzentLinks < 0 Then ProzentLinks = 0
If ProzentRechts < 0 Then ProzentRechts = 0
Links = CLng((CDbl(&HFFFF&) / 100) * ProzentLinks)
Rechts = CLng((CDbl(&HFFFF&) / 100) * ProzentRechts)
Lautstärke = CLng("&H" & Hex$(Rechts) &
_
String(4 - Len(Hex$(Links)), _
Asc("0")) & Hex$(Links))
waveOutSetVolume 0&, Lautstärke
End Sub