Play music when the application is in the background using kAudioSessionCategory_SoloAmbientSound

I want to play music when my application is in the background, so I installed

"background background"

in my info.plist application.

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

Is it possible?

If I set the category to kAudioSessionCategory_MediaPlayback , my application will be able to play music in the background, but when kAudioSessionCategory_SoloAmbientSound , when I press the home button on the device, it stops playing (and when I return to the foreground it plays music).

So, I want to play music in the background and β€œrespect” the mute state. Is it possible?

Thanks for your reply in advance!

+4
source share
1 answer

Apple told me that you need to use the MediaPlayback category to play sound in the background. More details here AVAudioPlayer using AmbientSound session does not play when the application is in the background

I need to solve the same problem with MediaPlayback, and then try to detect the mute state for replicating Ambient functions (or in your case AmbientSolo).

0
source

Source: https://habr.com/ru/post/1384324/


All Articles