我正在尝试检索播放列表的艺术作品(而不是歌曲的艺术作品)。 Apple音乐应用程序允许您为播放列表创建图像,但我似乎无法访问它。
这可能吗? MPMediaItemPropertyArtwork未列为播放列表属性键之一。
我正在尝试以下方法:
let playlistItems: [MPMediaPlaylist] = playlistQuery.collections! as! [MPMediaPlaylist]
for playlist in playlistItems {
let artwork = playlist.value( forProperty: MPMediaItemPropertyArtwork ) as? MPMediaItemArtwork
let sizeforArtwork = artwork?.bounds.size
let artworkImage = artwork?.image(at: sizeforArtwork!)
let playlistName = playlist.value( forProperty: MPMediaPlaylistPropertyName ) as! String
let info: PlaylistInfo = PlaylistInfo(
playlistTitle: playlistName,
playlistImage: artworkImage
)
playlists.append(info)
}
和
struct PlaylistInfo {
var playlistTitle: String
var playlistImage: UIImage?
}
var playlists: [PlaylistInfo] = []