How to detect musickit player's play state change in background

I'm using musickit on iOS 15 in my APP. I want to detect user change the player's play state when app enters the background.

For example when user play next song i need to detect the change to refresh my app's widget

Hello @zengxing,

If you're using MusicKit's ApplicationMusicPlayer, you should be able to get updates from the state object, which conforms to ObservableObject.

Following guidance from the documentation for ApplicationMusicPlayer, make sure to include a background audio mode in the Info.plist file for your app.

I hope this helps.

Best regards,

How to detect musickit player's play state change in background
 
 
Q