MPNowPlayingInfoCenter无法使用WKWebView播放

时间:2016-02-04 18:25:17

标签: ios wkwebview mpnowplayinginfocenter

我正在使用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替换为AVPlayerAVAudioPlayer,则此工作正常。

0 个答案:

没有答案