Playing music when application is in background with kAudioSessionCategory_SoloAmbientSound [duplicate]

StackOverflow https://stackoverflow.com/questions/8802427

Question

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!

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top