[SOLVED] Resume and Suspend - Audio problems

Hi there,

When I Suspend and resume my app on an iPad - the sound stops playing? I am on the latest build .929

Do I have to destroy all related objects and reload them again when the app is resumed?
Joakim [import]uid: 81188 topic_id: 31901 reply_id: 331901[/import]

No, you are not supposed to need to do anything. Corona is supposed to handle the suspend and automatically resume for you. It should behave the same as when you pull down notification center or double tap home to get the Dock.

This used to work. Which iOS versions are you using? If iOS 6, does it work in 5.1?

Apple is constantly breaking the suspend/resume stuff with audio. In 5.1 they broke Notification Center if-and-only-if you brought down Notification Center in response to a new notification and then left the app by tapping on the new notification. In 6.0, they broke the Siri/phone call interruption mechanism:
http://developer.coronalabs.com/forum/2012/09/22/audio-soundsstreams-not-working-after-invoking-siri-or-getting-phone-call

So it would not surprise me if you found a new bug. If you could tell us which iOS versions this affects (this is really important to know) plus tell us all the different ways you suspend that work or don’t work, this will help us isolate the problem.
[import]uid: 7563 topic_id: 31901 reply_id: 127238[/import]

Hi,

I am on iOS 6.0 and using the latest build from you. This happens when I press the “lock” key on my iPad and then resume it from the suspended mode. It seems to work as it should with the notification center.

I cant test it on 5.1 since I don’t have it installed anymore. We are uploading our game to appstore within three weeks, do you know if there are any workarounds for this?

Should I file a bug for this?

Edit: It works fine with the double tap on the “home” button as well.

Joakim [import]uid: 81188 topic_id: 31901 reply_id: 127240[/import]

Yes, please file a bug with us.
Also, if you can tell us if this worked in a previous version of Corona, that would be helpful.
As for workarounds, you might be able to manually pause/resume yourself. On the suspend event, pause or stop all channels. Then on resume, you can resume. I’m not sure if this will actually work and may depend on which iOS version you are running on.

[import]uid: 7563 topic_id: 31901 reply_id: 127249[/import]

Ok, but my project is way to big to upload when filling in a bug.

I will try the workaround to see if that works first.

Thanks, Joakim [import]uid: 81188 topic_id: 31901 reply_id: 127251[/import]

I’m poking at this because I’ve been looking at the Siri bug which is similar, but it’s starting to look like that Apple made a subtle breaking change which avoids triggering certain callbacks we relied on (applicationWillResignActive). This is actually not an audio specific bug and can break a bunch of other things including the OpenGL system. Would you please include what I just typed in your bug report.

Also, please post the bug number so I can track it.
[import]uid: 7563 topic_id: 31901 reply_id: 127254[/import]

No, you are not supposed to need to do anything. Corona is supposed to handle the suspend and automatically resume for you. It should behave the same as when you pull down notification center or double tap home to get the Dock.

This used to work. Which iOS versions are you using? If iOS 6, does it work in 5.1?

Apple is constantly breaking the suspend/resume stuff with audio. In 5.1 they broke Notification Center if-and-only-if you brought down Notification Center in response to a new notification and then left the app by tapping on the new notification. In 6.0, they broke the Siri/phone call interruption mechanism:
http://developer.coronalabs.com/forum/2012/09/22/audio-soundsstreams-not-working-after-invoking-siri-or-getting-phone-call

So it would not surprise me if you found a new bug. If you could tell us which iOS versions this affects (this is really important to know) plus tell us all the different ways you suspend that work or don’t work, this will help us isolate the problem.
[import]uid: 7563 topic_id: 31901 reply_id: 127238[/import]

Hi,

I am on iOS 6.0 and using the latest build from you. This happens when I press the “lock” key on my iPad and then resume it from the suspended mode. It seems to work as it should with the notification center.

I cant test it on 5.1 since I don’t have it installed anymore. We are uploading our game to appstore within three weeks, do you know if there are any workarounds for this?

Should I file a bug for this?

Edit: It works fine with the double tap on the “home” button as well.

Joakim [import]uid: 81188 topic_id: 31901 reply_id: 127240[/import]

Yes, please file a bug with us.
Also, if you can tell us if this worked in a previous version of Corona, that would be helpful.
As for workarounds, you might be able to manually pause/resume yourself. On the suspend event, pause or stop all channels. Then on resume, you can resume. I’m not sure if this will actually work and may depend on which iOS version you are running on.

[import]uid: 7563 topic_id: 31901 reply_id: 127249[/import]

Ok, but my project is way to big to upload when filling in a bug.

I will try the workaround to see if that works first.

Thanks, Joakim [import]uid: 81188 topic_id: 31901 reply_id: 127251[/import]

I’m poking at this because I’ve been looking at the Siri bug which is similar, but it’s starting to look like that Apple made a subtle breaking change which avoids triggering certain callbacks we relied on (applicationWillResignActive). This is actually not an audio specific bug and can break a bunch of other things including the OpenGL system. Would you please include what I just typed in your bug report.

Also, please post the bug number so I can track it.
[import]uid: 7563 topic_id: 31901 reply_id: 127254[/import]

I’m back from vacation and I just retested my case and also tested your sample app. My case works correctly.

Your sample case sets UIApplicationExitsOnSuspend=true in build.settings which will prevent your app from suspending. So that is actually working correctly.

I removed that line and on my iPad 3 with iOS 6, audio suspends/resumes correctly.

So I’m really confused now, but think things are working correctly. Would you please retest with build 935.

[import]uid: 7563 topic_id: 31901 reply_id: 128231[/import]

I’m back from vacation and I just retested my case and also tested your sample app. My case works correctly.

Your sample case sets UIApplicationExitsOnSuspend=true in build.settings which will prevent your app from suspending. So that is actually working correctly.

I removed that line and on my iPad 3 with iOS 6, audio suspends/resumes correctly.

So I’m really confused now, but think things are working correctly. Would you please retest with build 935.

[import]uid: 7563 topic_id: 31901 reply_id: 128231[/import]

Hmmm, yes we want our app to quit when the user closes the app from the home menu.

But, if the user locks the iPad by pressing the upper right button, and then unlock - the app is still running, and with no sounds. Same happens if the iPad closes when there has been non activity for a couple of minutes. Sometimes when we “mute” the game by the hardware button on the iPad, we get the same problems with the sound?

I am maybe wrong here, but I assume that this is a sound bug - or is it a UIApplicationExitsOnSuspend bugg?

Joakim
[import]uid: 81188 topic_id: 31901 reply_id: 128399[/import]

Hmmm, yes we want our app to quit when the user closes the app from the home menu.

But, if the user locks the iPad by pressing the upper right button, and then unlock - the app is still running, and with no sounds. Same happens if the iPad closes when there has been non activity for a couple of minutes. Sometimes when we “mute” the game by the hardware button on the iPad, we get the same problems with the sound?

I am maybe wrong here, but I assume that this is a sound bug - or is it a UIApplicationExitsOnSuspend bugg?

Joakim
[import]uid: 81188 topic_id: 31901 reply_id: 128399[/import]

You never said anything about screen locking. That is a different matter.

I think you found an Apple regression bug. iOS 5.0 seems to work better than iOS 6.0 in this matter. It might be related to the Siri bug. Please file a bug report with Apple. Like the Siri bug, the correct code is being run, but something inside Apple’s code is breaking.

As a workaround, you might be try to manually pause on suspend and resume on play. We are doing that automatically, but Apple has had race conditions in the past where commands get ignored.
[import]uid: 7563 topic_id: 31901 reply_id: 128535[/import]

I did some testing on other games that exits on suspend, on my iOS6 device. And they start play when the device is unlocked again.

Joakim [import]uid: 81188 topic_id: 31901 reply_id: 128624[/import]

Hmmmm…something strange is going on here. I just tried to manually start the sound but nothing happens. Any ideas, or am I doing something wrong here?

 function onSystemEvent( event )  
 if (event.type == "applicationSuspend") then  
 --os.exit()  
 audio.stop()  
 audio.dispose(bgmusic)  
 bgmusic = nil;  
  
 elseif (event.type == "applicationResume") then  
 bgmusic = audio.loadSound("sounds/mySafari.mp3")  
 print("bgmusic" , bgmusic) --Yes a valid LUA table...  
 audio.setVolume( 1, { channel=1 } )  
 audio.play(bgmusic,{channel = 1, loops=-1})  
 end  
 end  
 Runtime:addEventListener( "system", onSystemEvent )  

Joakim [import]uid: 81188 topic_id: 31901 reply_id: 128632[/import]

You never said anything about screen locking. That is a different matter.

I think you found an Apple regression bug. iOS 5.0 seems to work better than iOS 6.0 in this matter. It might be related to the Siri bug. Please file a bug report with Apple. Like the Siri bug, the correct code is being run, but something inside Apple’s code is breaking.

As a workaround, you might be try to manually pause on suspend and resume on play. We are doing that automatically, but Apple has had race conditions in the past where commands get ignored.
[import]uid: 7563 topic_id: 31901 reply_id: 128535[/import]

Sorry, I didn’t mean to imply the workaround would actually work. It was just an easy long shot thing to try. I think you found an Apple bug.

But I recommend you start with one of our simple Sample programs. Your Lua program you sent me has bugs which are triggering internal Corona warnings. It is possible the Lua bugs in your program are causing something else to break. But I noted that running your program on iOS 5.0 vs. iOS 6.0 had different behaviors which makes me say file an Apple regression bug ASAP.

[import]uid: 7563 topic_id: 31901 reply_id: 128660[/import]