3

I'm using WKWebView to play audio/video and am looking to set custom MPNowPlayingInfoCenter nowPlayingInfo, but WKWebView appears to override any settings that I make. Has anyone been able to add custom lockscreen controls and metadata while using WKWebView?

Here is a condensed example of the code that I am using:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

// ... create the WKWebView and play the video ...

NSMutableDictionary * const mutableNowPlayingInfo = [NSMutableDictionary dictionary];
mutableNowPlayingInfo[MPMediaItemPropertyArtist]            = [playlistItem videoCreator]  ?: @"";
mutableNowPlayingInfo[MPMediaItemPropertyTitle]             = [playlistItem videoName]     ?: @"";
mutableNowPlayingInfo[MPMediaItemPropertyPlaybackDuration]  = [playlistItem videoDuration] ?: @(0.0);
mutableNowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = @(1.0);

MPNowPlayingInfoCenter * const infoCenter = [MPNowPlayingInfoCenter defaultCenter];
[infoCenter setNowPlayingInfo:mutableNowPlayingInfo];

Note that -remoteControlReceivedWithEvent: is also overridden as necessary in my AppDelegate class.

Also note that this works fine if the WKWebView is swapped out for, say, an AVPlayer or AVAudioPlayer.

Aaron Wojnowski
  • 6,352
  • 5
  • 29
  • 46

0 Answers0