Search code examples
ioscocoa-touchhtmlaudiobackground

Continue playing audio from html5 player when in iOS background mode


We built our music-oriented app in html5 and javascript with Sencha touch. For distribution we wrapped it in xcode with UIwebView. Everything runs fine except one thing that does not work: audio playing in multitask mode.

I know the general idea: add the UIBackgroundModes in info.plist.

Done. Now we can play the audio even in background mode.

Until we reach the end of the song. To start the next song we have to bring the app to foreground again or we can hit the play or 'next song' button on the iPhone audio controller.

After some research I found a promising workaround at: " Entering background on iOS4 to play audio " where the workaround is to edit AVAudioSessionCategoryPlayback and work with the UIBackgroundTaskIdentifier. The problem for me is (just like in any other fix I found so far) that those solutions always assume that the audio is played either with AVaudioPlayer or MPMusicPlayerController. But in my case I user neither, our audio is played by our html5 player wrapped in UIwebView.

Anyone has any advice on how to continue playing the audio in iOS multitask mode when the audio player is a html5/javascript player?


Solution

  • Thanks, guys, but I ended up simply keeping the app busy in a loop when in background mode. This was enough to bridge the time when connecting to the next song on the playlist. The code I used is similar to this one: iPhone - Backgrounding to poll for events