I've got an iOS app build on Swift MusicKit that retrieves Apple Music tracks and presents them to a user in a list.
Tapping the track attempts to the track using this function:
func handlePlayThisTrack(track: AppleMusicTrack) async {
do {
let tracksToQueue = sortedTracks.compactMap{$0.track}
if let track = tracksToQueue.first(where: {$0.id.rawValue == track.id}) {
print("track", track)
player.queue = ApplicationMusicPlayer.Queue(for: tracksToQueue, startingAt: track )
try await player.play()
} else {
Logger.log(.error, "Track does not exist in sorted tracks!")
}
} catch {
print(error)
}
}
Sometimes, however, the track does not play, and checking the logs, I see the below.
This only happens on some tracks, but on those that don't work it happens consistently.
When printing the details for a track that doesn't work, it looks like this:
track Track.song(Song(id: "1443100129", title: "She's Not There", artistName: "The Zombies"))
And this looks like all the other tracks that do play.
So I don't know where to look for said missing play parameters
mentioned in the error.
I have an inkling that this may have to do with the track not being available due to the country/storefront, and that the error message is misleading.
I'm using the following to get the tracks:
MusicCatalogResourceRequest<Song>(matching: \.isrc, equalTo: isrc) // <= the ISRC of the track I want to fetch
My assumption is that the MusicCatalogResourceRequest would only respond with tracks in my country/storefront, but I think this may not be the case.
Is there any way to create a MusicCatalogRequest in such a way that I only get results that are playable in my country/storefront?
Any advice would be most appreciated. Thanks!
2022-02-25 02:24:56.971343+0700 MusicApp[19452:1186508] [Playback] Failed to insert MusicPlayer.Queue.Entry(id: "F6A04D56-F5C5-4628-B136-5438E188FDA5", transientItem: Track.song(Song(id: "1443100129", title: "She's Not There", artistName: "The Zombies"))) into queue descriptor because it's missing play parameters.
2022-02-25 02:24:57.102432+0700 MusicApp[19452:1186733] [Entitlements] MSVEntitlementUtilities - Process MusicApp PID[19452] - Group: (null) - Entitlement: com.apple.accounts.appleaccount.fullaccess - Entitled: NO - Error: (null)
2022-02-25 02:24:57.104579+0700 MusicApp[19452:1186733] [core] Attempted to register account monitor for types client is not authorized to access: {(
"com.apple.account.iTunesStore"
)}
Hello @Kimfucious,
Thank you very much for bringing this issue to our attention.
There is currently no way to create a MusicCatalogResourceRequest with MusicKit in such a way that you only get results that are playable.
We believe there are things we might be able to do to on our end that would improve this aspect of the API, and we will keep investigating this further.
Meanwhile, if you need an immediate solution to this problem, I suppose you could always filter the items of the MusicCatalogResourceResponse to only include instances of Song that have non-nil playParameters.
I hope this helps.
Best regards,