ApplicationMusicPlayer.shared.state.playbackStatus unexpected results

Hi -

Of course I may be doing something wrong, but I'm getting exactly the opposite of what I would expect from

ApplicationMusicPlayer.shared.state.playbackStatus

It returns .playing when the music is paused and .paused when the music is playing.

Am I holding it wrong?

Thanks,

Daniel

Replies

Hello @dimsumthinking,

The main thing to know about MusicPlayer.State is that it conforms to ObservableObject, thus making it very easy to use with SwiftUI. The primary way that it's designed to be used is in a SwiftUI View, using ObservedObject.

Please refer to our official sample app to see an example of how this can be used: Using MusicKit to Integrate with Apple Music

It would definitely help for you to share a bit more about how you're trying to use ApplicationMusicPlayer.shared.state.playbackStatus. Using that outside of a SwiftUI View is possible, but it might require special care to catch object changes at the right time.

I hope this helps.

Best regards,