Cannot Start Audio Playback from Interactive Widget (iOS 17)

I want to be able to start/stop audio from my interactive widget.

But when I try to start playback with my AppIntent, I get the error,

ATAudioSessionClientImpl.mm:281 activation failed. status = 561015905

This indicates the app isn't set up properly for background audio, but it has Audio, AirPlay, and Picture in Picture checked in Background Modes.

Is this an intentional limitation of 3rd party widgets?

The Apple Music widget is able to start and stop audio without the app being in the foreground. Can third party apps do it too?

Accepted Reply

I figured it out.

I just found this: https://developer.apple.com/documentation/appintents/audioplaybackintent

  • Still doesn't work! Getting the same error even after confirming to AudioPlaybackIntent. Maybe there is something which I'm still missing. How did you managed to get it work with Interactive Widget Buttons? Do we have to activate AVAudioSession ?

  • It only seems to work if you play the audio strait away with no asynchronous code. I only got it to work with a simple test app that just plays an audio file. however it didn’t always work in my app which needs to fetch audio asynchronously before playing. Don’t know what I’m doing wrong

  • I've finally got this functionality up and running. It was necessary to configure the AVAudioSession category as '.playback' and subsequently activate the AVAudioSession.

Replies

I figured it out.

I just found this: https://developer.apple.com/documentation/appintents/audioplaybackintent

  • Still doesn't work! Getting the same error even after confirming to AudioPlaybackIntent. Maybe there is something which I'm still missing. How did you managed to get it work with Interactive Widget Buttons? Do we have to activate AVAudioSession ?

  • It only seems to work if you play the audio strait away with no asynchronous code. I only got it to work with a simple test app that just plays an audio file. however it didn’t always work in my app which needs to fetch audio asynchronously before playing. Don’t know what I’m doing wrong

  • I've finally got this functionality up and running. It was necessary to configure the AVAudioSession category as '.playback' and subsequently activate the AVAudioSession.

For those still struggling with this - make sure that your widget code has target membership for your widget extension AND your iOS app. This is required otherwise the background audio capability doesn't work. What's frustrating is it works on the simulator even if the iOS app isn't included in the target membership. If you run on a real device you'll get the error. Make sure you include both targets!!