Playing audio while your app is backgrounded.

Score one for the Miracle Man!!!

For the app I built for my son’s music blog, he has a podcast section and some of the audio clips are quite long. Feedback on the app was "You need to play audio in the background. I was convinced that I would have to re-write it in Objective C to take advantage of this.

I googled around to figure out what I needed to do and came across a snippet that said you just need to add a flag to your Info.plist file.

I thought, “Hmm, I wonder???” Brought up the editor, opened build.settings and added this block to my plist block:

 UIBackgroundModes = {  
 "audio"  
 },  

Built a device version, started a podcast and hit the sleep button… Music played. Went back, hit the home button… music played. Had my son call me. Music interrupted, took the call, hung up, music resumed…

all with those 3 lines of code. Note UIBackgroundModes requires an array passed to it, ergo the string inside the curlies.

Have fun with this little tidbit. Corona SDK and Ansca, you Rock more than you know!

BRILLIANT!!

Now I hope I don’t get rejected because I set the minimum iOS at 3.2.0 and this is a 4.0 feature. [import]uid: 19626 topic_id: 13926 reply_id: 313926[/import]

Thanks for sharing Rob :smiley:

A lot of people get stuck on this - I’m going to save a link to this for next time it comes up.

Peach :slight_smile: [import]uid: 52491 topic_id: 13926 reply_id: 51278[/import]

If you use Corona Project Manager you can set that up easily, it’s available as an option when you config your project. [import]uid: 13560 topic_id: 13926 reply_id: 51282[/import]