2015-05-04 70 views
7

我想創建一個包含來自YouTube和Soundcloud的音軌的多源音樂播放器,並且我想覆蓋MPNowPlayingInfoCenter的內容以提供有關藝術家/發佈的信息而不是名稱YouTube視頻。在使用WKWebView時覆蓋MPNowPlayingInfoCenter

一切運作良好,當我用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 

我檢查了沒有我用的都是零,我激活了我的AudioSession中的變量AppDelegate

var audioSession = AVAudioSession.sharedInstance() 
var error : NSError? 
audioSession.setCategory(AVAudioSessionCategoryPlayback, error: &error) 
audioSession.setActive(true, error: &error) 
UIApplication.sharedApplication().beginReceivingRemoteControlEvents() 

任何想法?

+0

被你能找到這個解決方案?只花一天的時間試圖找到一種方法來覆蓋WKWebView和UIWebView提供的信息在鎖屏上(我想提供一個UIImage和文本自己..)沒有成功..順便說一句:與IOS 8.4和UIWebView,我也不能設置鎖定屏幕圖像 – cujo30227

+0

不,我終於放棄了,並沒有iOS 8和WKWebview NowPlayingInfos應用程序我在蘋果雷達上創建了一個問題,但到目前爲止我還沒有任何答案,它已經超過3幾個月,iOS 9的情況依然如此,所以我不認爲他們會做任何事情 –

回答

2

雖然不可能覆蓋iOS上的屬性本身,應該注意的是,改變「稱號的」 <video>元素的屬性在JavaScript

我已經實現了這一行爲與

var control = ...; //Create video DOM control 
control.title = "Desired title";