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.
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
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?
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
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()
Any ideas?
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";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With