Pause audio from all other apps

Hi there,


I've taken over a project from a previous developer which is pretty much complete. The idea is that in certain conditions, the app pauses all other audio (it's a utility sort of thing).


There are however, some problems with how the pausing functionality is implemented.


The code currently pauses audio by using the AVAudioSession library, specifically by using interruptSpokenAudioWithOthers in setCategory().


See the code example below:


func pauseAudio() {
        let audioSession = AVAudioSession.sharedInstance()
        do {
            try audioSession.setCategory(AVAudioSessionCategoryPlayback, with:.interruptSpokenAudioAndMixWithOthers)
            try audioSession.setActive(true)
        } catch let error as NSError {
            debugPrint(error)
        }
    }


It is my understanding that this is not how Apple intends this functionality to be used, and will likely fail their approval process. It also has the issue that a recent update to iOS seems to forcibly end the audio session after a few minutes if the app itself plays no audio or does not end the session itself.


I haven't been able to find any documentation on how to achieve this effect any other way. The closest I could find was the API for controlling the system music player, though this only works with the built in iOS music app.


Can anyone help me out here? Is there another, correct, way to pause all audio?


Thanks!

Replies

In general, iOS APIs are sandboxed for the express reason of preventing one app from breaking other apps (e.g. by interrupting their audio). I would be very surprised if there was any legit way to accomplish what you ask. That “feature” is a non starter.

>haven't been able to find any documentation on how to achieve this effect any other way


There is a simple reason you're coming up dry. Your app isn't allowed that level of global device control.