guinness, And after all that, here is a suggested function which will play both mp3 and wav files:
#AutoIt3Wrapper_Res_File_Add=Basic.mp3, RT_RCDATA, BASICMP3
#AutoIt3Wrapper_Res_File_Add=Basic.wav, SOUND, BASICWAV
#include "ResourcesEx.au3"
MsgBox($MB_SYSTEMMODAL, "Sound", "Play mp3")
$iRet = _Resource_PlaySound_Mod("BASICMP3")
MsgBox($MB_SYSTEMMODAL, "Sound", "Play wav")
$iRet = _Resource_PlaySound_Mod("BASICWAV")
Func _Resource_PlaySound_Mod($sResNameOrID, $iFlags = $SND_SYNC, $sDLL = Default)
Local $bIsInternal = ($sDLL = Default Or $sDLL = -1)
Local $hInstance = ($bIsInternal ? 0 : _WinAPI_LoadLibraryEx($sDLL, $LOAD_LIBRARY_AS_DATAFILE))
If $iFlags = Default Then $iFlags = $SND_SYNC
Local $bReturn
; Try to read resource into memory
Local $binSound = _Resource_GetAsBytes($sResNameOrID) ; Assume mp3 so look in RT_RCDATA
; Get file size
Local $iFileSize = @extended
If $iFileSize = 0 Then
; Assume a wav
$bReturn = _WinAPI_PlaySound($sResNameOrID, BitOR($SND_RESOURCE, $iFlags), $hInstance)
Else
; Convert mp3 to hybrid wav
$sHdr_1 = "0x52494646"
Local $sHdr_2 = "57415645666D74201E0000005500020044AC0000581B0000010000000C00010002000000B600010071056661637404000000640E060064617461"
Local $sAlign_Buffer = "00"
Local $sMp3 = StringTrimLeft(Binary($binSound), 2)
Local $iMp3Size = StringLen($sMp3)
; Convert to required format
Local $iMp3Size = StringRegExpReplace(Hex($iFileSize, 8), "(..)(..)(..)(..)", "$4$3$2$1")
Local $iWavSize = StringRegExpReplace(Hex($iFileSize + 63, 8), "(..)(..)(..)(..)", "$4$3$2$1")
; Construct hybrid wav file
Local $sHybridWav = $sHdr_1 & $iWavSize & $sHdr_2 & $iMp3Size & $sMp3
If Mod($iMp3Size, 2) Then
$sHybridWav &= $sAlign_Buffer
EndIf
; Create struct
Local $tWave = DllStructCreate("byte[" & BinaryLen($sHybridWav) & "]")
DllStructSetData($tWave, 1, $sHybridWav)
; Set flag
$iFlags = BitOR($SND_MEMORY, $SND_NODEFAULT, $iFlags)
; Play sound
DllCall("winmm.dll", "int", "PlaySoundW", "struct*", $tWave, "ptr", 0, "dword", $iFlags)
$bReturn = (@error ? 0 : 1)
EndIf
If Not $bIsInternal Then _WinAPI_FreeLibrary($hInstance)
Return $bReturn
EndFunc ;==>_Resource_PlaySound_Mod
Note that an mp3 needs to be inserted as RT_RCDATA and a wav as SOUND - that acts as the switch in the code. M23