是否可以检索音乐播放列表作品?

时间:2016-12-10 10:31:52

标签: ios swift3 playlist artwork

我正在尝试检索播放列表的艺术作品(而不是歌曲的艺术作品)。 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] = []

0 个答案:

没有答案