Implementing audio controls using ActivityKit

Is there a way to implement controls for background audio using ActivityKit like in the Apple Music application? I didn't found anything in your documentation about handling actions like this except deep links, but they're not suitable for this use case

Replies

You will need to implement a Toggle or Button that calls an App Intent which can run code in your app to work with audio in your app or using the systemMusicPlayer for controlling the current audio such as Apple Music.

For App Intents in general, some guidance:

  1. If your app intent is compiled only into your Widget Extension, it will only run in your Widget Extension.
  2. If your app intent is also compiled into your app, it will run in your app if your app is currently running and not suspended.
  3. If you want your app intent to always run in your app, you can:
  • implement openAppWhenRun, in which case it'll foreground your app OR
  • implement AudioIntent, LiveActivityIntent or ForegroundContinuableIntent in which case it'll run in your app, but run in the background.