Search code examples
iosswiftswift3media-playerios10

MPMediaItemPropertyArtwork is not displayed in command center


I am using an AVPlayer to play a music stream from a server. I have an artwork image that I want to display on both command center and lock screen. I am using the following code :

    let image = UIImage(named: "RadioBackground")!
    let artwork = MPMediaItemArtwork.init(boundsSize: image.size, requestHandler: { (size) -> UIImage in
        return image
    })

    var playingInfo:[String: Any] = [:]

    playingInfo[MPMediaItemPropertyArtwork] = artwork
    playingInfo[MPNowPlayingInfoPropertyPlaybackRate] = NSNumber(value: 1.0)

    MPNowPlayingInfoCenter.default().nowPlayingInfo = playingInfo

    UIApplication.shared.beginReceivingRemoteControlEvents()
    let CommandCenter = MPRemoteCommandCenter.shared()
    CommandCenter.playCommand.isEnabled = true
    CommandCenter.playCommand.addTarget(self, action:#selector(PlayPauseRadio))

    CommandCenter.pauseCommand.isEnabled = true
    CommandCenter.pauseCommand.addTarget(self, action:#selector(PlayPauseRadio))

The problem is that the artwork is only displayed on the lock screen, not on the command center.

Did I miss something ?


Solution

  • Ok I got it ! Finally ! You just have to set some property to your NowPlayingInfo. Here is the properties :

    MPMediaItemPropertyTitle