Interactive Widget & INPlayMediaIntent

I'm playing around with Interactive Widgets and I am trying to make one that starts playing audio content without bringing the app to the foreground.

The new Button used in interactive widgets accepts an AppIntent, but INPlayMediaIntent doesn't conform to AppIntent.

Starting to play something directly from an AppIntent doesn't seem to work either. The system kills my process if I try to call the following from an AppIntent:

''' try! AVAudioSession.sharedInstance().setActive(true) '''

I don't have a solution for you, I'll just mention that I managed to have an AppIntent to play audio without bringing the app to the foreground. It's audio the app knows and doesn't need to be given media information. The app gets launched if needed, and not brought to foreground (this by not implementing openAppWhenRun in my intent).

In the shortcuts app I see my app intents, I tap the audio playing one there and it works fine.

The problem is I cannot get to use this intent from an interactive widget because the intent depends on stuff in the main app target that isn't decoupled and I cannot bring it all to the widget extension.

Edit: even if I decoupled my audio playing code, I'd still probably be unable to play audio from the widget, based on your test and considering any code that runs is in the widget extension, not the main app. Having shared code between app and extension will be of no use if I can't get the actual app to be running just like when I tap the intent in the shortcuts app.

Interactive Widget & INPlayMediaIntent
 
 
Q