1

I am trying to retrieve the image of the currently playing song in the native music app. I can retrieve the title, artist, and album, but when I try to set the image of the artwork nothing happens.

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))
    }
manatee
  • 185
  • 1
  • 10
  • maybe that song doesn't have any cover image. Have you verified that? – JLT May 31 '16 at 05:29
  • It does have a cover image, I am playing from a specific playlist accumulated from Apple Music – manatee May 31 '16 at 05:34
  • You may refer to this post, although the answer is not in swift but I think you can understand the logic. http://stackoverflow.com/questions/25998621/mpmediaitemartwork-is-null-while-cover-is-available-in-itunes – JLT May 31 '16 at 05:37

0 Answers0