我正在使用WKWebView
来播放音频/视频,并希望设置自定义MPNowPlayingInfoCenter
nowPlayingInfo
,但WKWebView
似乎会覆盖我所做的任何设置。有没有人能够在使用WKWebView
时添加自定义锁屏控件和元数据?
以下是我正在使用的代码的简要示例:
[[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];
请注意,我-remoteControlReceivedWithEvent:
课程中的AppDelegate
也会被覆盖。
另请注意,如果将WKWebView
替换为AVPlayer
或AVAudioPlayer
,则此工作正常。