我正在使用Swift 3创建一个iOS应用程序,其中显示有关锁定屏幕和控制中心当前正在播放的项目的信息将是不错的.
目前,我正在使用以下代码尝试将此信息插入到nowPlayingInfo字典中.我还包括对使用的VideoInfo类的引用videoBeganPlaying(_:).
class VideoInfo {
var channelName: String
var title: String
}
// ...
var videoInfoNowPlaying: VideoInfo?
// ...
@objc private func videoBeganPlaying(_ notification: NSNotification?) {
// apparently these have to be here in order for this to work... but it doesn't
UIApplication.shared.beginReceivingRemoteControlEvents()
self.becomeFirstResponder()
guard let info = self.videoInfoNowPlaying else { return }
let artwork = MPMediaItemArtwork(boundsSize: .zero, requestHandler:
{ (_) -> UIImage in #imageLiteral(resourceName: "DefaultThumbnail") }) // this is filler
MPNowPlayingInfoCenter.default().nowPlayingInfo = …Run Code Online (Sandbox Code Playgroud)