我WKWebView
用来播放音频/视频并希望设置 custom 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
替换为例如 anAVPlayer
或,则此方法可以正常工作AVAudioPlayer
。