How to get user's most play songs and albums on apple music by apple music api.
Post
Replies
Boosts
Views
Activity
I want get song object from SystemMusicPlayer.Queue use musickit . But there's often crash .
Here is my code
func getSongData(complection:@escaping (Song)->())
{
Task.detached {
do {
let queue : SystemMusicPlayer.Queue?
queue = SystemMusicPlayer.shared.queue
if queue?.currentEntry != nil
{
let request = MusicCatalogResourceRequest<Song>(matching: \.id, equalTo: MusicItemID(rawValue: queue?.currentEntry?.item?.id.rawValue ?? "1595045323"))
let response = try? await request.response()
complection((response?.items.first)!)
}
}
}
}
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.