为什么当前正在播放的歌曲的艺术作品图像没有出现?

时间:2016-05-31 05:26:29

标签: ios swift mpmusicplayercontroller

我正在尝试检索原生音乐应用中当前正在播放的歌曲的图像。我可以检索标题,艺术家和专辑,但是当我尝试设置艺术作品的图像时,没有任何事情发生。

if let nowPlaying = musicPlayer.nowPlayingItem {
        let title = nowPlaying[MPMediaItemPropertyTitle] as? String
        let artist = nowPlaying[MPMediaItemPropertyArtist] as? String
        let album = nowPlaying[MPMediaItemPropertyAlbumTitle] as? String
        let duration = nowPlaying[MPMediaItemPropertyPlaybackDuration] as? NSNumber
        let artwork = nowPlaying[MPMediaItemPropertyArtwork] as? MPMediaItemArtwork
        print("Artwork: \(artwork?.description)") //prints: Artwork: Optional(<MPConcreteMediaItemArtwork: 0x1756bc90>)
        print("Song: \(title)")
        print("Artist: \(artist)")
        print("Album: \(album)")
        controltitle.text = title!
        controlartist.text = artist!
        artworkimage.image = artwork!.imageWithSize(CGSize(width: artworkimage.bounds.width, height: artworkimage.bounds.height))
    }

0 个答案:

没有答案