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"
)}
2
1
3.5k