fb:porticula NoPaste
Einfacher WinAPI-Sound
Uploader: | Cherry |
Datum/Zeit: | 16.01.2009 18:05:53 |
#Include "windows.bi"
#Include "win/mmsystem.bi"
#Include "vbcompat.bi"
Dim Shared MCIAliases(4095) As String
Function MCIPlaySound(filename_ As String) As Integer
Var filename = Trim(Ucase(filename_))
Dim soundalias As String
For i As Integer = 0 To 4095
If MCIAliases(i) = filename Then soundalias = "SPMCIPS" & Format(i, "0000"): Exit For
Next
If soundalias = "" Then
For i As Integer = 0 To 4095
If MCIAliases(i) = "" Or i = 4095 Then
mciSendString("close SPMCIPS" & Format(i, "0000"), NULL, 0, 0)
Function = 1
If mciSendString("open " & Chr(34) & filename & Chr(34) & " alias SPMCIPS" & Format(i, "0000"), NULL, 0, 0) = FALSE Then
Function = 0
MCIAliases(i) = filename
mciSendString ("set SPMCIPS" & Format(i, "0000") & " time format milliseconds", NULL, 0, 0)
soundalias = "SPMCIPS" & Format(i, "0000")
Endif
Exit For
Endif
Next
Endif
If soundalias <> "" Then
mciSendString("play " & soundalias & " from 0", NULL, 0, 0)
Endif
End Function
Sub MCIUnloadAll()
For i As Integer = 0 To 4095
mciSendString("close SPMCIPS" & Format(i, "0000"), NULL, 0, 0)
Next
End Sub
' Benutzungsbeispiel:
MCIPlaySound("c:\windows\media\tada.wav")
Sleep 2000
MCIPlaySound("c:\windows\media\chimes.wav")
Sleep 2000
MCIPlaySound("c:\windows\media\ding.wav")
Sleep 2000
MCIPlaySound("c:\windows\media\chimes.wav")
Sleep 2000
MCIUnloadAll()