Buchempfehlung
Visual Basic 6 Kochbuch
Visual Basic 6 Kochbuch
Viele praktische Tipps zum Programmieren mit Visual Basic 6, die sich oft auch auf FB übertragen lassen. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Einfacher WinAPI-Sound

Uploader:MitgliedCherry
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()