我正在尝试在锁定屏幕中显示命令中心而不是为我醒来, 我看到了本教程中的代码,并编写了相同的代码但也无法正常工作 https://github.com/lukagabric/LGAudioPlayerLockScreen
这是代码
var nowPlayingInfo = [MPMediaItemPropertyTitle: currentPlaybackItem.trackName,
MPMediaItemPropertyAlbumTitle: currentPlaybackItem.albumName,
MPMediaItemPropertyArtist: currentPlaybackItem.artistName,
MPMediaItemPropertyPlaybackDuration: audioPlayer.duration,
MPNowPlayingInfoPropertyPlaybackRate: NSNumber(value: 1.0 as Float)] as [String : Any]
if let image = UIImage(named: currentPlaybackItem.albumImageName) {
nowPlayingInfo[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(image: image)
}
self.nowPlayingInfoCenter.nowPlayingInfo = nowPlayingInfo
任何人都可以提供帮助
最佳答案
我注意到在尝试更新正在播放的信息字典时,您必须用数据填充键,即使是空字符串也是如此。
你确定 trackName
, albumName
, artistName
不是 nil 吗?
ModernAVPlayer有一个很好的例子:检查这个“NowPlaying”code
关于ios - Swift:远程命令中心不显示在 lockScreen 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53986069/