在使用WKWebView时覆盖MPNowPlayingInfoCenter

9

我正在尝试创建一个从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()

有什么想法?


你能找到解决方案吗?我花了一天的时间试图找到一种覆盖WKWebView和UIWebView并在锁屏界面上提供信息的方法(我想自己提供UIImage和文本..),但没有成功..顺便说一下:在IOS 8.4和UIWebView中,我也无法再设置锁屏图片了。 - cujo30227
不,我最终放弃了,在没有iOS 8和WKWebview的NowPlayingInfos的情况下发布了应用程序。 我在Apple Radar上创建了一个问题,但到目前为止我还没有得到任何答案,已经过去了3个多月,而且在iOS 9中情况仍然是一样的,所以我不认为他们会做任何事情。 - Marc Peysale
嘿,伙计们!@cujo30227 你解决了吗?我也遇到了同样的问题。但已经过去3.5年了!有什么解决办法吗? - Kesha Antonov
不好意思,还是一样的问题。 - cujo30227
1个回答

4
尽管在iOS上无法覆盖属性本身,但应注意,在JavaScript中更改<video>元素的"title"属性是可以实现的。
我已经通过下面的方法实现了这个行为。
var control = ...; //Create video DOM control
control.title = "Desired title";

2
设置图片怎么样? - quemeful

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接