Soundplay not working

Get help with using AutoHotkey and its commands and hotkeys
scriptor2016
Posts: 538
Joined: 21 Dec 2015, 02:34

Soundplay not working

02 Mar 2019, 21:39

Hi

Soundplay has stopped working on my system. I've tried 2 different approaches to play a .wav file:

Code: Select all

z::
soundplay, C:\Click.wav
and

Code: Select all

FilePath := "C:\Click.wav"
DllCall("winmm.dll\PlaySound", AStr, FilePath, uint, 0, uint, 0)
Every script in my collection that used soundplay has stopped playing the sounds all of a sudden. Soundbeep works, however.

My guess is that it's either something to do with AHK or is it perhaps a soundcard issue? I have ensured that AHK's volume is at 100% via the sound control panel.

Otherwise, all music/sounds, etc. play normally on my PC as they should - there are no other audio problems or issues on my computer.

Is this a familiar problem with a fix?

Thank you
gregster
Posts: 3379
Joined: 30 Sep 2013, 06:48

Re: Soundplay not working

02 Mar 2019, 22:38

If it worked before and stopped suddenly but you didn't update AHK... it most likely has a non-AHK reason. (I know of no related bug.)
Have you tried it with a mp3 instead?

Is Errorlevel = 1 ?
Does SoundPlay *-1 beep?
scriptor2016
Posts: 538
Joined: 21 Dec 2015, 02:34

Re: Soundplay not working

02 Mar 2019, 23:05

No, SoundPlay *-1 does not make any sounds. MP3 files don't work either.

Code: Select all

z::
soundplay, C:\Click.wav
SoundPlay *-1
 

if ErrorLevel = 1
msgbox, 1
 
if ErrorLevel = 0
msgbox, 0
the messagebox returns 0.

This is bizarre - all other sound is totally fine on my system.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Soundplay not working

03 Mar 2019, 00:00

You could try this, and see what the results are.

Code: Select all

q:: ;test PlaySound
;SND_FILENAME := 0x20000 ;source: playsoundapi.h
vPath := "C:\Windows\Media\tada.wav"
vRet := DllCall("winmm\PlaySound" (A_IsUnicode?"W":"A"), Str,vPath, Ptr,0, UInt,0x20000)
MsgBox, % vRet "`r`n" A_LastError
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
scriptor2016
Posts: 538
Joined: 21 Dec 2015, 02:34

Re: Soundplay not working

03 Mar 2019, 00:22

There is no sound.

The messagebox returns:

1
0
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Soundplay not working

03 Mar 2019, 01:22

- I got 1 and 0 and the sound played. Btw you should check to confirm that the file actually exists, because I got 1 and 0 when I changed the path to a non-existent filename.
- You could try AHK 64-bit and AHK 32-bit.
- Which OS is it?
- Did you try restarting the computer?
- I don't really have more to say beyond what I've said. Best of luck.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
scriptor2016
Posts: 538
Joined: 21 Dec 2015, 02:34

Re: Soundplay not working

03 Mar 2019, 01:59

thanks jeeswg, appreciated. I am on Windows7 64-Bit. I am running AHK version 1.1.22.03 (Unicode 32-bit). This is actually a problem that happened many months ago, but only now am I tackling it. Soundplay used to work perfectly, but somewhere along the lines something has gone wrong. Restarting the PC makes no difference.

Should I be upgrading/changing my version of AHK maybe?
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Soundplay not working

03 Mar 2019, 02:15

- You could try downloading a newer version, and running your script with that. (I have no particular reason to think it'll work, but it's possible.)
- It's also possible to try SoundPlay in AutoIt or try using the Winapi with another programming language.
- (Other things would be checking the volume settings, and mentioning if you had any hunches re. possible causes.)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
scriptor2016
Posts: 538
Joined: 21 Dec 2015, 02:34

Re: Soundplay not working

03 Mar 2019, 02:26

alright, I will try these few things and report back :)
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Soundplay not working

03 Mar 2019, 02:40

- Btw I think in some situations, the PC has been so busy that SoundPlay has been delayed. (I had a script that detected window events and signalled those events via SoundPlay.)
- In which case it's feasible that some amount of activity by another program or programs on the PC would delay/affect SoundPlay.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
scriptor2016
Posts: 538
Joined: 21 Dec 2015, 02:34

Re: Soundplay not working

03 Mar 2019, 03:58

this is nuts. This works:

Code: Select all

q::
Soundbeep
but this doesn't work:

Code: Select all

q::
SoundPlay, %A_WinDir%\Media\ding.wav
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Soundplay not working

03 Mar 2019, 04:27

So, some long shot ideas might be: closing other programs, running the script as admin, trying 64-bit/32-bit AHK. And trying say AutoIt or another programming language, might confirm that the problem is not to do with AutoHotkey.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
scriptor2016
Posts: 538
Joined: 21 Dec 2015, 02:34

Re: Soundplay not working

03 Mar 2019, 04:29

Okay, here's a very strange update:

I own a Logitech Headset, model #H800

If I run:

Code: Select all

Run, mmsys.cpl
it opens my system output sound properties. My default playback mode is:

Speakers
Realtek High Definition Audio
Default Device

and in this mode, my system sound works perfectly. However, AHK will not play any sounds in this mode.


BUT- if I change my output sound properties to:

Speakers
Logi H800 Headset
Default Device


...then I can hear all AHK sounds using soundplay through my headset.

This is totally bizarre. What could be causing this?
scriptor2016
Posts: 538
Joined: 21 Dec 2015, 02:34

Re: Soundplay not working

03 Mar 2019, 16:32

well, looks like it was a bug in the soundcard settings. I switched back and forth between different output settings (in the soundcard software, NOT in the "Run, mmsys.cpl" sound properties panel). Toggling back and forth through all the available output options (speakers, headset, digital output, digital optical output, etc etc) seems to have reset something - and now it works. Strange but at least I have soundplay working again.

Thanks for all the help guys :)

Return to “Ask For Help”

Who is online

Users browsing this forum: Odlanir, pn4265 and 242 guests