有没有办法防止AVPlayerViewController通过MPNowPlayingInfoCenter更新锁屏界面?

3

我的问题是:

我有一个播放音频文件的应用程序,通过MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo更新锁屏信息,这部分工作正常。

但在另一个视图中,我正在使用AVPlayerViewControllerAVPlayer播放视频,当视频开始播放时,它会自动更新锁屏,除了视频持续时间外没有任何内容。

我在 Apple 的文档中没有找到关于此行为的任何内容,我找不到禁用它的方法。

到目前为止,我尝试在视频开始播放之前调用UIApplication.sharedApplication().endReceivingRemoteControlEvents(),并在之后调用beginReceivingRemoteControlEvents()。它不起作用。

有人知道如何防止这种情况发生吗?


更新:我没有找到一个适当的方法来解决它(在iOS10以下),所以当应用程序进入后台时,我暂停视频(使其对MPNowPlayingInfoCenter“不可见”),并使用当前歌曲信息更新nowPlayingInfo。 - Jérémy Lapointe
1个回答

5

iOS 10开始,AVPlayerViewController中有一个名为updatesNowPlayingInfoCenterBOOL属性,默认值为YES。只需将其更改为NO:

//playerController is an instance of AVPlayerViewController
if ([self.playerController respondsToSelector:@selector(setUpdatesNowPlayingInfoCenter:)])
{
    self.playerController.updatesNowPlayingInfoCenter = NO;
}

谢谢提供信息! - Jérémy Lapointe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接