How to handle background audio playing while iOS device is locked or on another application?

gluon picture gluon · May 3, 2012 · Viewed 52.8k times · Source

Designing a generative music system for iOS, using OpenFrameworks, I'd need to provide a mode in which the user could listen the music produced by the application when:

  • the device is locked
  • the user uses another application

Some applications like BLOOM, or alarm clock, works like that and propose to users a switch to enable/disable this feature.

Any tips for that ?

Answer

DanSkeel picture DanSkeel · May 3, 2012

Playing Background Audio

An app that plays or records audio continuously (even while the app is running in the background) can register to perform those tasks in the background. You enable audio support from the Background modes section of the Capabilities tab in your Xcode project. (You can also enable this support by including the UIBackgroundModes key with the audio value in your app’s Info.plist file.) Apps that play audio content in the background must play audible content and not silence.

Apple reference "Playing and Recording Background Audio"

Ensuring That Audio Continues When the Screen Locks

For enabling/disabling this feature I found Activating and Deactivating Your Audio Session, I haven't tried it myself, but it looks like what you need.