When testing my app on device, I noticed it would it appeared to function correctly and work well. But if the device ( iPhone 6Plus and IPad2 ) ‘suspended’ app, when I tap home button or whatever to resume the app, the app still functions as it should, except absolutely no audio plays. If I then press home button to suspend it again, and then resume the app again, the audio restores and plays. I spent 3 days going over my app and all it’s functions, testing the timing of various audio calls, figuring that some line of code or timer in my app was causing this problem.
I did not want to trouble the forum community with this question if I thought it was something I had wrong in my code, so I decide to just test with a simple and basic app to see if same issue occurs, and it does. It just occurs inconsistently … not every time it goes into suspend and resumes. Wether it is 6 seconds or 10 seconds or 10 minutes later (I have tested repeatedly) it does it fail … but it does only sometimes. At times it seemed like there was a pattern, that is every other time I suspended and then resumed say 7-8 seconds later - it failed, and every other time it played audio. But, then I had 3,4, or 5 successful times where the audio played, before the next resume failed.
Maybe this was discussed at some time in the past on the forums. I am sorry if I missed it, I did search internet and the forums and only saw an audio issue after resume ‘years’ ago pertaining to Android, and the thought I believe then was something with Android OS… but I am testing so far just on apple - 6Plus and Ipad2.
You might say, pause all timers on suspend and resume them on system resume… good idea. I did that as you can see in my second simple code example below… and it also ‘failed audio completely’, and that means even the button click that is not on a timer fails to play. It doesn’t happen all the time, not even every other time like I thought the pattern showed; but it does happen. However, it does seem to happen less often with the pause and resume timer code in place. I think I went about 4 times in a row when it did not fail, then on the next it did.
SDK 2017.3163
IOS on iphone 11.2
Anyone have experience with this. Is there a work around. I do not see anything in this simple test code, that should create this issue. Here is the simple test code:
local sound1 = audio.loadSound("Audio/boom.wav") local function runSFX() audio.play(sound1) end timer.performWithDelay(3000, runSFX, -1)
Here is the test code with pause and resume of timers on suspend and resume of system
local widget = require("widget") local sfxTimer local sound1 = audio.loadSound("Audio/boom.wav") local click = audio.loadSound("Audio/click.mp3") local function runSFX() audio.play(sound1) end local function onButton(e) if e.phase == "ended" then audio.play(click) print("button pressed and released") end end local button = widget.newButton{ defaultFile = "Textures/bar.png", overFile = "Textures/bar\_dn.png", onEvent = onButton } button.x = 150 button.y = 150 local function onSystemEvent( event ) if (event.type == "applicationExit") then elseif (event.type == "applicationOpen") then elseif (event.type == "applicationResume") then sfxTimer.resume() elseif (event.type == "applicationSuspend") then sfxTimer.pause() end end sfxTimer = timer.performWithDelay(3000, runSFX, -1)
Thanks
Bob