Hemisphere Games Banner

App switching and graceful music handling in iOS

We post few dev/technical pieces on our blog (I’d love to do more), but we ran into an issue recently that seems to plague many iOS apps on the store: Music not always playing on app resume. It’s not catastrophic when it happens – and can often be fixed by hitting the home button and trying again – but it is annoying.

It may be OpenAL related, but we’re not entirely sure to be honest. (Many more games use OpenAL than we thought at first. Apparently the list includes Angry Birds, Cut the Rope, Flight Control, Bumpy Road, Bit Pilot, Flower Garden, etc.) At first we thought we had a bug in Osmos, but on testing other apps we discovered it’s a fairly widespread issue.

To reproduce it, try switching back and forth (by double-tapping on the Home button) between the current store versions of Flight Control and Flower Garden. After a couple of swaps you’ll find that music in Flight Control often doesn’t resume. Depending on which pair of apps you choose to test you’ll end up with slightly different results — like an extra-complex game of rock-paper-scissors. (Angry Birds Space has impeccable manners though. It always recovers gracefully, and any app that comes after recovers nicely as well. I knew there was a reason behind Rovio’s success!)

So what’s going on here? Well, on startup/resume most apps will check to see if other audio is playing (eg. music or a podcast in iTunes) via a call like

   AudioSessionGetProperty(
      kAudioSessionProperty_OtherAudioIsPlaying,
      &propertySize,
      &audioIsAlreadyPlaying);


If audioIsAlreadyPlaying turns out to be true, polite games will refrain from playing their own music. Sometimes, however, audioIsAlreadyPlaying appears to be true even when it shouldn’t be. Why? It seems to be a timing issue. (Warning: speculation.) It may be that the previous app hasn’t “finished” moving to the background when the new app takes over, giving the new app a temporarily misleading view of the situation.

The solution? (Thanks to Eric Johnson of Semi Secret Software for this tip!) Keep re-polling the status of kAudioSessionProperty_OtherAudioIsPlaying every couple seconds after starting up. Trying a few times over the course of 10 seconds or so ought to do it! We did this for Osmos, and it’s recovering very reliably now.

5 Comments on “App switching and graceful music handling in iOS”

  1. #1 eddybox
    on Jul 6th, 2012 at 6:01 pm

    ps. The store version will continue to suffer from these issues until we submit our next update of course. ;-)

  2. #2 Daniel
    on Jul 7th, 2012 at 12:35 pm

    It’s always interesting this kind of behind-the-scenes stuff. Thanks for posting it.

  3. #3 Dev Links: Cleaning Up | The Indie Game Magazine - Indie Game Reviews, Previews, News & Downloads
    on Jul 22nd, 2012 at 5:58 am

    [...] App Switching And Graceful Music Handling In iOS (Hemisphere Games) “We post few dev/technical pieces on our blog (I’d love to do more), but we ran into an issue recently that seems to plague many iOS apps on the store: Music not always playing on app resume. It’s not catastrophic when it happens – and can often be fixed by hitting the home button and trying again – but it is annoying.” [...]

  4. #4 Dev Links: Cleaning Up | DIYGamer
    on Jul 22nd, 2012 at 12:58 pm

    [...] App Switching And Graceful Music Handling In iOS (Hemisphere Games) “We post few dev/technical pieces on our blog (I’d love to do more), but we ran into an issue recently that seems to plague many iOS apps on the store: Music not always playing on app resume. It’s not catastrophic when it happens – and can often be fixed by hitting the home button and trying again – but it is annoying.” [...]

  5. #5 Luma repair cream
    on Aug 22nd, 2014 at 1:44 pm

    I don’t even understand how I ended up right here, however I thought this
    post was great. I do not recognize who you might be however certainly you’re going to a famous blogger
    when you aren’t already. Cheers!

    my webpage – Luma repair cream

Leave a Comment