4

I want to play music when my application is in the background, so I've set

"audio background mode"

in my app's info.plist.

I want to set the audiosession's category to kAudioSessionCategory_SoloAmbientSound, because I want to respect the mute switch, and I don't want to mix with other applications.

Is this possible?

If I set the category to kAudioSessionCategory_MediaPlayback then my app is able to play music in background, but with kAudioSessionCategory_SoloAmbientSound when I press the home button on the device, it stops playing (and when I return back to the foreground it returns playing music).

So I want to play music in background, and "respect" the mute switch's state. Is that possible?

Thanks for your answer in advance!

Community
  • 1
  • 1
stoflow
  • 163
  • 1
  • 10

1 Answers1

0

Apple have told me that for sound to be played in the background you need to use the MediaPlayback category. More details here AVAudioPlayer, using AmbientSound session, is not playing when app is in background

I am having to solve this same problem by using MediaPlayback and then trying to detect the mute switch state to replicate the functionality of Ambient (or in your case AmbientSolo).

Community
  • 1
  • 1
Simon East
  • 2,406
  • 2
  • 16
  • 21
  • "then trying to detect the mute switch state to replicate the functionality of Ambient" - Unfortunately there isn't any option to achieve this... There were some code around, but they aren't working with never iOS versions. Based on an Apple engineer they don't support to request the mute switch's state. The only option is to use the Ambient/AmbientSolo. – stoflow May 08 '12 at 17:18
  • As far as I can tell there is no way to make audio play in background and obey mute switch - more detail in my answer here: http://stackoverflow.com/questions/8763942/avaudioplayer-using-ambientsound-session-is-not-playing-when-app-is-in-backgro/8801259#8801259 – Simon East May 09 '12 at 20:07