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

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

문제

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!

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top