我正在使用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))
问题是艺术作品只显示在锁定屏幕上,而不是显示在指挥中心上。
我错过了什么吗?
答案 0 :(得分:0)
好的我明白了!最后!您只需要为NowPlayingInfo
设置一些属性即可。这是属性:
MPMediaItemPropertyTitle