SoundPlay, Pre-Loading? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
bapl
Posts: 119
Joined: 17 Apr 2021, 00:24

SoundPlay, Pre-Loading?

13 Sep 2022, 22:44

Hello!

I would like to know a couple of questions about how Sound Play works, namely:

1. Is there a download every time SoundPlay is called, or only 1 time during the entire operation of the script?
2. I saw an example example for Ahk v1 with a call to PlaySound, How to make it work on V2?

Code: Select all

Start := FileRead("Assets\Sound\Suspend Off.wav", "RAW")
PlaySound(Start)
Sleep 1000

PlaySound( &Sound ) {
Return DllCall("winmm.dll\PlaySound" ( 1 ? "W" : "A" ), "UInt", Sound, "UInt", 0
, "UInt", ((SND_MEMORY:=0x4)|(SND_NODEFAULT:=0x2)))
}
I get the error:
Error: Parameter #1 of PlaySound requires a variable reference, but
received a Buffer.

I want the file to be loaded in advance into memory for later playback. How to implement it correctly?
bapl
Posts: 119
Joined: 17 Apr 2021, 00:24

Re: SoundPlay, Pre-Loading?

14 Sep 2022, 06:42

pls, any help?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: SoundPlay, Pre-Loading?  Topic is solved

14 Sep 2022, 07:52

Code: Select all

PlaySound( Sound ) {
Return DllCall("winmm.dll\PlaySound" ( 1 ? "W" : "A" ), "Ptr", Sound, "UInt", 0
, "UInt", ((SND_MEMORY:=0x4)|(SND_NODEFAULT:=0x2)))
}
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: SoundPlay, Pre-Loading?

25 Apr 2023, 21:50

swagfag wrote:
14 Sep 2022, 07:52

Code: Select all

PlaySound( Sound ) {
Return DllCall("winmm.dll\PlaySound" ( 1 ? "W" : "A" ), "Ptr", Sound, "UInt", 0
, "UInt", ((SND_MEMORY:=0x4)|(SND_NODEFAULT:=0x2)))
}
Hello, i am actually searching for quite similar thing,
could you explain me more of the code?
where do i insert it? on top?
and where do i put my mp.3 path?

i want to pre-load

Code: Select all

SoundPlay A_ScriptDir (on ? '\Say Hello.mp3' : '\Joker.mp3')
Thanks :)
0w0Demonic
Posts: 1
Joined: 07 May 2023, 14:26

Re: SoundPlay, Pre-Loading?

08 Mar 2024, 09:13

Maybe this helps:

Code: Select all

filepath := a_desktop "\vine-boom.wav"
sound := fileread(filepath, "RAW")
msgbox("variable 'sound' is of type " type(sound))
msgbox("Mem location of 'sound': " sound.ptr)

playsound(sound) {
	dllcall(
		"winmm.dll\PlaySoundW", ; try "A"-version in case you have a 32-bit system
		"uint", sound.ptr, ; pass the memory location of the buffer
		"uint", 0,
		"uint", 6 ; (2 | 4)
	)
}

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 19 guests