有没有办法阻止AVPlayerViewController通过MPNowPlayingInfoCenter更新锁定屏幕?
问题描述:
这里是我的问题: 我有一个应用程序播放音频文件,通过MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo
更新锁屏信息,这部分工作正常。有没有办法阻止AVPlayerViewController通过MPNowPlayingInfoCenter更新锁定屏幕?
但在另一种观点中,我在播放AVPlayerViewController
和AVPlayer
的视频,当视频开始播放时,它自动更新锁定屏幕,除视频持续时间外没有任何内容。
我没有在Apple的文档中找到有关此行为的任何信息,我无法找到禁用它的方法。
到目前为止,我已经尝试在视频开始播放之前拨打UIApplication.sharedApplication().endReceivingRemoteControlEvents()
,之后尝试拨打beginReceivingRemoteControlEvents()
。它不起作用。
有没有人知道一种方法来防止这种情况?
答
与iOS 10开始有一个BOOL
财产AVPlayerViewController
称为updatesNowPlayingInfoCenter
,具有默认值:YES
。只需将其更改为NO
:
//playerController is an instance of AVPlayerViewController
if ([self.playerController respondsToSelector:@selector(setUpdatesNowPlayingInfoCenter:)])
{
self.playerController.updatesNowPlayingInfoCenter = NO;
}
+0
感谢您的信息! –
更新:我没有找到合适的办法解决它(以下iOS10),所以当应用程序在后台得到,我暂停视频(这使得它“隐形“到MPNowPlayingInfoCenter),并使用当前歌曲信息更新nowPlayingInfo。 –