使用WKWebView时覆盖MPNowPlayingInfoCenter [英] Overriding MPNowPlayingInfoCenter while using WKWebView
问题描述
我正在尝试创建一个具有来自YouTube和Soundcloud的曲目的多源音乐播放器,并且我想覆盖MPNowPlayingInfoCenter的内容以提供有关歌手/发行人的信息,而不是YouTube视频的名称.
I am trying to create a multi-source music player with tracks coming from YouTube and Soundcloud, and I would like to override the content of MPNowPlayingInfoCenter to provide informations about the artists/releases instead of the name of the YouTube video.
使用UIWebview时一切正常,但是出于性能原因,我不得不切换到新的WKWebview,现在我之前用来设置nowPlayingInfos的方法无效
Everything worked well when I used UIWebview, but for performance reasons, I had to switch to the new WKWebview and now the method I used before to set the nowPlayingInfos has no effect
有没有办法禁用HTML中<audio>
和<video>
标签的自动映射和/或覆盖它随我的信息提供的信息?
Is there a way to disable the automatic mapping of the <audio>
and <video>
tags inside the HTML and/or to override the infos it provides with my infos?
这是我使用的代码,该代码在iOS 7上运行,在使用UIWebview时在iOS 8上运行:
Here's the code that I use which works on iOS 7 and worked on iOS 8 when I used UIWebview:
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
I checked that none of the variables I use are nil, and I activated my AudioSession in the AppDelegate
var audioSession = AVAudioSession.sharedInstance()
var error : NSError?
audioSession.setCategory(AVAudioSessionCategoryPlayback, error: &error)
audioSession.setActive(true, error: &error)
UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
有什么想法吗?
推荐答案
尽管在iOS上无法覆盖该属性本身,但应注意,在JavaScript中更改<video>
元素的"title"属性
Although it's impossible to override the property itself on iOS, it should be noted that changing the "title" property of the <video>
element in JavaScript
我已经通过以下方式实现了这种行为
I've achieved this behaviour with
var control = ...; //Create video DOM control
control.title = "Desired title";
这篇关于使用WKWebView时覆盖MPNowPlayingInfoCenter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!