#If Win32 Then
Private Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As Any, ByVal uFlags As Long) As Long
#Else
Private Declare Function sndPlaySound Lib "MMSYSTEM.DLL" _
(ByVal lpszSoundName As Any, ByVal wFlags As Integer) As Integer
#End If
Const SND_ASYNC = &H1 ' Play asynchronously
Const SND_NODEFAULT = &H2 ' Don't use default sound
Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
Private Sub Command1_Click()
Dim ret() As String
Dim StrHeader As String
Dim FileLength As Long
Dim FileB() As Byte
Inet1.URL = "http://www.wav-sounds.com/cartoon/daffyduck1.wav"
Inet1.Execute , "GET", , "Range: bytes=" & CStr(0) & "-" & vbCrLf
Do While Inet1.StillExecuting
DoEvents
Loop
StrHeader = Inet1.GetHeader("Content-Range")
If InStr(1, StrHeader, "/") Then
ret = Split(StrHeader, "/")
FileLength = CLng(ret(1))
End If
FileB = Inet1.GetChunk(FileLength, icByteArray)
Dim SndRet As Long
Dim soundbuffer As String
#If Win32 Then
' Important: The returned string is converted to Unicode
soundbuffer = StrConv(FileB, vbUnicode)
#Else
soundbuffer = LoadResData(FileB, "Sounds")
#End If
SndRet = sndPlaySound(soundbuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)
' Important: This function is neccessary for playing sound asynchronously
DoEvents
End Sub