我正在尝试创建一个从YouTube和Soundcloud获取音轨的多源音乐播放器,并且我希望覆盖MPNowPlayingInfoCenter的内容,提供有关艺术家/发布版本的信息,而不是YouTube视频名称。
当我使用UIWebview时一切都有效,但由于性能原因,我不得不切换到新的WKWebview,现在我之前用来设置nowPlayingInfos的方法没有效果了。
是否有一种方法可以禁用HTML中<audio>
和<video>
标记的自动映射,并/或者用我的信息覆盖它提供的信息?
这是我使用的代码,在iOS 7上有效,在我使用UIWebview时在iOS 8上也有效:
let newInfos = [
MPMediaItemPropertyTitle: (currentPlaylist[currentPlaylistIndex] as! Track).trackName,
MPMediaItemPropertyArtist: (currentPlaylist[currentPlaylistIndex] as! Track).trackArtist,
MPMediaItemPropertyPlaybackDuration: NSNumber(integer: self.getDuration()),
MPNowPlayingInfoPropertyElapsedPlaybackTime: NSNumber(integer: self.getCurrentTime()),
MPNowPlayingInfoPropertyPlaybackRate: NSNumber(double: self.playing ? 1.0 : 0.0),
MPMediaItemPropertyArtwork: MPMediaItemArtwork(image: image)
]
MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = newInfos
我检查了使用的所有变量都不是空值,并在AppDelegate中激活了我的AudioSession。
var audioSession = AVAudioSession.sharedInstance()
var error : NSError?
audioSession.setCategory(AVAudioSessionCategoryPlayback, error: &error)
audioSession.setActive(true, error: &error)
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
有什么想法?