I have some warning sounds in my app but I really need background music (e.g. Spotify) to keep running in the background. I solved this by
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
However, in silent mode my AVAudioPlayer
s are muted but the sound is crucial, even in silent mode. I read about AudioServicesPlaySystemSound
ignoring silent mode but it does not, at least not on iOS9.
Any other possibilities? Oh and please waste your time by saying things like "I would hate this as a user", "isn't it called SILENT mode", ... this is a programming page, not a philosophy class.
Go to Settings > Accessibility > Audio/Visual > Background Sounds, then turn on Background Sounds. Set any of the following: Sound: Choose a sound; the audio file downloads to your iPhone. Volume: Drag the slider.
The Audio Session Category AVAudioSessionCategoryAmbient will obey the Ring/Silent switch as stated in the documentation -
AVAudioSessionCategoryAmbient The category for an app in which sound playback is nonprimary—that is, your app can be used successfully with the sound turned off...
... Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).
I suggest trying a better suited category with mixing options like -
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:nil];
AVAudioSessionCategoryPlayback category will ignore the silent switch as mentioned in documentation -
When using this category, your app audio continues with the Silent switch set to silent or when the screen locks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With