How to get system music queue from MusicKit?

I'm using MusicKit to build an iOS app that manages the queue of Apple Music. I am able to get the current item in the queue by:

SystemMusicPlayer.shared.queue.currentEntry

And I can subscribe to changes in the queue with:

cancellable = SystemMusicPlayer.shared.queue.objectWillChange.sink(receiveValue: { _ in
    print("Received value: \(SystemMusicPlayer.shared.queue.currentEntry)")
})

However, I'm unable to figure out how I can get the upcoming items in the queue. Does anyone know how to do this with the new MusicKit API?

Answered by Frameworks Engineer in 713916022

Hello @pranavwadhwa,

MusicKit has two different concrete types of MusicPlayer: SystemMusicPlayer and ApplicationMusicPlayer.

They're designed for completely different use-cases, and I urge you to watch our WWDC session from 2021, Meet MusicKit for Swift. Starting at 13 min and 28 seconds in the video, you can learn about playback APIs in MusicKit, and understand the differences between these two players.

The specific piece of information that's relevant to answer your question is that SystemMusicPlayer's queue only gives apps access to the currentEntry. So there is no way to achieve what you're asking about using SystemMusicPlayer.

However, if you determined that ApplicationMusicPlayer was suitable for your app, then you would have access to a more feature rich music player, whose queue exposes not only the currentEntry, but also a collection of all the entries in the music player queue.

I hope this helps.

Best regards,

Hello @pranavwadhwa,

MusicKit has two different concrete types of MusicPlayer: SystemMusicPlayer and ApplicationMusicPlayer.

They're designed for completely different use-cases, and I urge you to watch our WWDC session from 2021, Meet MusicKit for Swift. Starting at 13 min and 28 seconds in the video, you can learn about playback APIs in MusicKit, and understand the differences between these two players.

The specific piece of information that's relevant to answer your question is that SystemMusicPlayer's queue only gives apps access to the currentEntry. So there is no way to achieve what you're asking about using SystemMusicPlayer.

However, if you determined that ApplicationMusicPlayer was suitable for your app, then you would have access to a more feature rich music player, whose queue exposes not only the currentEntry, but also a collection of all the entries in the music player queue.

I hope this helps.

Best regards,

How to get system music queue from MusicKit?
 
 
Q