User Library Songs and ArtworkImage

What is the correct way to use the new ArtworkImage view with songs from the user's library?

I'm fetching the songs using MPMediaQuery.songs, since I want the user's entire library, which provides MPMediaItems with an MPMediaItemArtwork. I can't see a way to get an Artwork for use with ArtworkImage from this. I could manually fetch the artwork by using a MusicCatalogResourceRequest for each song or I could (very slowly) fetch the user's library using MusicDataRequest with /v1/me/library/songs?include=catalog, but neither seem correct.

(I could use MusicCatalogResourceRequest per album, which would reduce the requests, but I'd like to display track specific artwork when available (e.g. Brian Eno's Music for Installations))

Thank you

Replies

Hello @tgt,

There is no simple way to use MusicKit's ArtworkImage to display artwork for an instance of MPMediaItem from MediaPlayer.

Another idea to accomplish the same result is indeed to load content from Apple Music API's endpoint to get all library songs using MusicDataRequest.

However, if that's not appropriate for your use-case, then I think your best bet is to create your own SwiftUI view that calls MPMediaItemArtwork's image(at:) method to retrieve an instance of UIImage. Then, you can pass that to SwiftUI's Image(uiImage:) initializer.

I hope this helps.

Best regards,