I'm trying to write a little mod for myself that turns on background sound when a ready check fires because I tend to alt-tab a lot during downtime in raids but don't want background sound on all the time.
My problem is that setting background sound to on seems to take some time to propagate or something. Using the code I have below, the first time I get a ready check, the bg sound setting gets turned on but I can't hear the sound in the background. However, without changing anything else, if I send a second ready check, that one works. Does anyone know how to avoid this issue (or a better way to do what I'm trying to do)? Thanks.
local frame = CreateFrame("FRAME", nil, ReadyCheckListenerFrame)
ReadyCheckListenerFrame:SetScript("OnShow", nil)
local bgSound = nil
local function BgSoundOn()
bgSound = BlizzardOptionsPanel_GetCVarSafe("Sound_EnableSoundWhenGameIsInBG")
if(bgSound == 0) then
AudioOptionsSoundPanelSoundInBG:SetValue(1)
end
print(BlizzardOptionsPanel_GetCVarSafe("Sound_EnableSoundWhenGameIsInBG"))
end
local function BgSoundOff()
if(bgSound == 0) then
AudioOptionsSoundPanelSoundInBG:SetValue(0)
end
end
function ReadyCheckListenerFrame_OnShow()
print("ReadyCheckListenerFrame_OnShow")
BgSoundOn()
PlaySound("ReadyCheck")
--BgSoundOff()
end
frame:SetScript("OnShow", ReadyCheckListenerFrame_OnShow)
It does take a moment to register volume changes, so what you can do is play the sound manually after a specific interval (say, 1 second) from detection of the ready check.
Actually is there some way to delay 2 seconds without using OnUpdate? OnUpdate doesn't fire when I'm alt-tabbed out of the game.
Nope. OnUpdate is the only way to delay something by X amount of time. If you used another library to do this, say AceTimer, AceTimer would itself be using an OnUpdate to do it as a wrapper for you.
The OnUpdate bug is quite specific though, OnUpdates currently only stop firing if you are using full-screen mode and are alt-tabbed out, so users in window mode (maximised or not irrelevant) do not have this issue. This issue's supposed to be fixed in the next patch.
Thanks, changing to maximized windowed mode did in fact fix the OnUpdate bug. However, I have a new issue now. As far as I can tell, the "propagation" for changing the sound setting isn't time based - it requires me to actually alt-tab back into the game for at least some sliver of time. Is there some better way of doing what I'm trying to do or am I just SOL?
Thanks, changing to maximized windowed mode did in fact fix the OnUpdate bug. However, I have a new issue now. As far as I can tell, the "propagation" for changing the sound setting isn't time based - it requires me to actually alt-tab back into the game for at least some sliver of time. Is there some better way of doing what I'm trying to do or am I just SOL?
From how you explain it, it seems like the game checks if "sound in background" is enabled while losing focus and disables the sound if needed. It then seems to only enable the sound when it regains focus.
In other words, it doesn't seem like changing the "sound in background" setting itself can directly disable/re-enable sound.
I haven't tried this myself, but the next thing I would try doing is changing the actual "enable sound" setting.
In other words, when you're normally auto-setting the Sound in BG on. Do the following: Disable Sound, Enable Sound in BG, Enable Sound. See if that "forces" the sound to be enabled.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
My problem is that setting background sound to on seems to take some time to propagate or something. Using the code I have below, the first time I get a ready check, the bg sound setting gets turned on but I can't hear the sound in the background. However, without changing anything else, if I send a second ready check, that one works. Does anyone know how to avoid this issue (or a better way to do what I'm trying to do)? Thanks.
Nope. OnUpdate is the only way to delay something by X amount of time. If you used another library to do this, say AceTimer, AceTimer would itself be using an OnUpdate to do it as a wrapper for you.
The OnUpdate bug is quite specific though, OnUpdates currently only stop firing if you are using full-screen mode and are alt-tabbed out, so users in window mode (maximised or not irrelevant) do not have this issue. This issue's supposed to be fixed in the next patch.
From how you explain it, it seems like the game checks if "sound in background" is enabled while losing focus and disables the sound if needed. It then seems to only enable the sound when it regains focus.
In other words, it doesn't seem like changing the "sound in background" setting itself can directly disable/re-enable sound.
I haven't tried this myself, but the next thing I would try doing is changing the actual "enable sound" setting.
In other words, when you're normally auto-setting the Sound in BG on. Do the following: Disable Sound, Enable Sound in BG, Enable Sound. See if that "forces" the sound to be enabled.