Hi, I currently have a program with a little radio. If I tap on the radio when it’s off (or turning off), static sfx occurs and at the end of the static audio music plays. If I tap the radio when it’s on (or turning on), then the music stops and static sfx occurs.
I’m currently having an issue when I turn the radio off then back on quickly. Sometimes the music doesn’t play. After looking further into this I noticed that in those circumstances where the radio wasn’t playing… audio.play returned 0.
Why might audio.play not play a sound and instead return 0? I’m usually never using more than like 4 or so channels.
In case it might help pinpoint the problem… my code:
local function stopChannel(key) print("Trying to stop channel: " .. key .. ": " .. tostring(channelTable[key])) if channelTable[key] and channelTable[key] \> -1 then audio.stop(channelTable[key]) print("Stopped channel: " .. key .. ": " .. tostring(channelTable[key])) end channelTable[key] = -1 end local function activate() if not radioObj then return; end if radioObj.state == "turnOff" or radioObj.state == "off" then print("Radio: Turn On") -- Audio audio.pause(channelTable["background"]); radioObj.state = "turnOn" stopChannel("radio") channelTable["radio"] = audio.play(soundTable["radioStatic"], { onComplete = function(e) if e.completed then print("Radio: On") -- 1. State radioObj.state = "on"; petObj.hasDanced = false; -- 2. Audio stopChannel("radio") channelTable["radio"] = audio.play(soundTable["radioMusic"], {loops = -1}) -- THIS IS RETURNING ZERO SOMETIMES print("Playing Radio Music on channel: " .. channelTable["radio"]) end end }) print("Playing Radio Static on channel: " .. channelTable["radio"]) radioObj:bounce({minXScale = 0.98}) elseif radioObj.state == "turnOn" or radioObj.state == "on" then print("Radio: Turn Off") -- 1. State radioObj.state = "turnOff"; -- 2. Animate radioObj:stopAfterBounce(); -- 3. Audio stopChannel("radio") channelTable["radio"] = audio.play(soundTable["radioStatic"], { onComplete = function(e) if e.completed then print("Radio: Off") stopChannel("radio") audio.resume(channelTable["background"]); radioObj.state = "off" end end }) end end
Thank you very much!