MPMediaItemPropertyArtwork未显示在命令中心中

时间:2017-04-26 21:45:49

标签: ios swift swift3 media-player ios10

我正在使用AVPlayer播放来自服务器的音乐流。我有一个艺术品图像,我想在命令中心和锁定屏幕上显示。我使用以下代码:

    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))

问题是艺术作品只显示在锁定屏幕上,而不是显示在指挥中心上。

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

好的我明白了!最后!您只需要为NowPlayingInfo设置一些属性即可。这是属性:

MPMediaItemPropertyTitle