Mit DirectSound geht das auch ohne externe DLL:
AutoIt
#include "DirectSound.au3"
#include <Array.au3>
Global $aDevice = _DSnd_Enumerate()
_ArrayDisplay($aDevice)
Global $aSND1 = _SND_Play("Test.wav", 2)
Global $aSND2 = _SND_Play("Test.mp3", 3)
While _SND_IsPlaying($aSND1) Or _SND_IsPlaying($aSND2)
ToolTip("Sound1: " & StringFormat("%.1f", _SND_GetPosition($aSND1) * 100) & "%" & @CRLF & "Sound2: " & StringFormat("%.1f", _SND_GetPosition($aSND2) * 100) & "%")
Sleep(100)
WEnd
_SND_Stop($aSND1)
_SND_Stop($aSND2)
Func _SND_Play($sFile, $iDevice = 1, $fVolume = 1)
Local $aWav = _DSnd_WaveLoadFromFile($sFile)
If @error Then
Local $hFile = FileOpen($sFile, 16)
Local $bFile = FileRead($sFile)
FileClose($hFile)
$aWav = _DSnd_MP3Decode($bFile)
EndIf
If Not IsArray($aWav) Then Return SetError(1, 0, False)
Switch $aWav[1].FormatTag
Case $WAVE_FORMAT_MPEG, $WAVE_FORMAT_MPEGLAYER3
$aWav = _DSnd_MP3Decode($aWav[0])
If @error Then Return SetError(1, 1, False)
EndSwitch
Local $aDevice = _DSnd_Enumerate()
If @error Or Not IsArray($aDevice) Then Return SetError(1, 2, False)
If $iDevice < 1 Then
$iDevice = 1
ElseIf $iDevice > $aDevice[0][0] Then
$iDevice = $aDevice[0][0]
EndIf
Local $aSND[3]
$aSND[0] = _DSnd_Create($aDevice[$iDevice][2])
$aSND[1] = _DSnd_CreateSoundBuffer($aSND[0], BitOR($DSBCAPS_GLOBALFOCUS, $DSBCAPS_CTRLVOLUME), BinaryLen($aWav[0]), $aWav[1].Channels, $aWav[1].SamplesPerSec, $aWav[1].BitsPerSample, $aWav[1].FormatTag)
$aSND[2] = BinaryLen($aWav[0])
Local $aLock = _DSnd_BufferLock($aSND[1])
Local $tBuffer = DllStructCreate("byte[" & $aLock[1] & "];", $aLock[0])
DllStructSetData($tBuffer, 1, $aWav[0])
_DSnd_BufferUnLock($aSND[1], $aLock)
_SND_SetVolume($aSND, $fVolume)
_DSnd_BufferPlay($aSND[1])
Return $aSND
EndFunc ;==>_SND_Play
Func _SND_Stop(ByRef $aSND)
If Not IsArray($aSND) Or UBound($aSND) <> 3 Then Return SetError(1, 0, False)
$aSND[1].Stop()
$aSND[1] = 0
$aSND[0] = 0
$aSND = 0
EndFunc ;==>_SND_Stop
Func _SND_SetVolume($aSND, $fVolume)
If Not IsArray($aSND) Or UBound($aSND) <> 3 Then Return SetError(1, 0, False)
If $fVolume < 0.00001 Then
$fVolume = 0.00001
ElseIf $fVolume > 1 Then
$fVolume = 1
EndIf
Local $fDB = 20 * Log($fVolume) / Log(10)
$aSND[1].SetVolume($fDB * 100)
EndFunc ;==>_SND_SetVolume
Func _SND_IsPlaying($aSND)
If Not IsArray($aSND) Or UBound($aSND) <> 3 Then Return SetError(1, 0, False)
Local $iStatus
$aSND[1].GetStatus($iStatus)
Return BitAND($iStatus, $DSBSTATUS_PLAYING)
EndFunc ;==>_SND_IsPlaying
Func _SND_GetPosition($aSND)
If Not IsArray($aSND) Or UBound($aSND) <> 3 Then Return SetError(1, 0, False)
Local $iPos
$aSND[1].GetCurrentPosition($iPos, Null)
Return $iPos / $aSND[2]
EndFunc ;==>_SND_GetPosition
Alles anzeigen
Die benötigte DirectSound-UDF findest du in meinem Anhang