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:
- If your app intent is compiled only into your Widget Extension, it will only run in your Widget Extension.
- 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.
- 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.