3
votes

Is it possible to play audio with AVAudioPlayer in the background and also mute it with the mute switch on iPhone?

I know I can play audio in the background if I set AVAudioSessionCategoryPlayback but it will not mute with the mute switch. Or if I set AVAudioSessionCategoryAmbient - it will be muted by a switch but also when pressing home button for example - and I don't want that to happen.

UPDATE: I have "App plays audio or streams audio.." in "Required background modes" - so when i set AVAudioSessionCategoryPlayback it continues playing in background even after pressing home button but the mute switch has no effect.

1
Have you looked at UIBackgroundModes. I think you can use it with AVAudioSessionCategoryAmbient. But not sure if will also work with the home button.markhunte
I'm not sure but i don't think this is possible without AudioSessionCategories and be careful about your app may be rejected by apple if you will solve it with some tricky way. Good luckYucel Bayram
@yucelbayram i didn't say i didnt wanted to use AudioSessionCategories. If you have solution using them - it will be great.Stals
I did not try mute it with switch button before sorry but did you check this answers? maybe there is something useful for you. stackoverflow.com/questions/287543/…Yucel Bayram
@yucelbayram i just thought it is normal behaviour when you can mute all sound with the mute switch - even if something is playing in background.Stals

1 Answers

1
votes

No, the desired behaviour is not possible with the available AVAudioSession categories. This might be on purpose to avoid unwanted battery loss or data costs for the users. Users can still decide to lower the volume to zero with the volume buttons of course.

Since there is also no public API anymore to detect the status of the silent/mute switch anymore, workarounds/hacks are tricky and might be declined on App Store submission.