Shared AVAudioPlayer State Between App and Widget: How does Apple Music Do It?

Hello Everyone,

I'm working on creating an audio playback widget for my app, aiming for functionality similar to the Apple Music widget. Specifically, I've implemented a play button in my widget that triggers an AudioPlaybackIntent. This intent then interacts with a singleton class that manages my AVAudioPlayer.

The issue I'm facing is that the AVAudioPlayer instance in my main app and the instance in my widget extension don't seem to share the same state. I've noticed that the Apple Music widget is capable of showing real-time changes (eg. stopping music from command center, stops it on widget UI), which implies that it has some way of sharing the playback state between the main app and the widget.

How can I achieve shared state between the main app and widget for my AVAudioPlayer instance? Is there a specific approach or API that Apple Music uses to make this happen?

Post not yet marked as solved Up vote post of DavJwk Down vote post of DavJwk
471 views
  • The problem concerns iOS 17 Beta

  • did you find any solution?

Add a Comment

Replies

did you find any solution?