I'm using SimpleAudioEngine to play background music. If I put my iPhone to sleep and then immediately wake it back up, the sound continues to play, as it should. However if it goes to sleep for a longer period of time and then wake it up, the background music does not resume playing, but a few minutes later while playing the game it will start up right in the middle. I tried pausing and resuming in the resign callbacks with no luck.
No Background Music on resume
(6 posts) (2 voices)-
Posted 1 year ago #
-
Have you set the resign behavior? If not then the operating system handles pausing and resuming your music so it sounds like it is a bug in the OS. Try executing this command after you have first accessed the shared SimpleAudioEngine - you need to be using the latest version of SimpleAudioEngine for this to work.
[[CDAudioManager sharedManager] setResignBehavior:kAMRBStopPlay autoHandle:YES];Posted 1 year ago # -
Thanks Steve,
I was not aware of the resign handler in Denshion. I will give this a try tonite. So I don't need anything in applicationWillResignActive or applicationDidBecomeActive? Will this just pause the song or restart from the beginning?
Posted 1 year ago # -
kAMRBStopPlay will stop the background music and then restart it from where it left off. You absolutely do not want to use pause, you must use stop. The operating system automatically unpauses any paused AVAudioPlayers upon resume, whether it paused them or not.
If you use autoHandle = YES like in the code I gave then you don't need to do anything, anywhere.
Posted 1 year ago # -
What kind of time period do I need to wait? I have tested kAMRBStopPlay with a 10 minute delay, is that enough for the problem to become apparent?
Posted 1 year ago # -
I never did pin down the time period. However, I implemented your suggestion and left the device in sleep mode over night and the next morning the music resumed as it should. Thanks!
Posted 1 year ago #
Reply
You must log in to post.