Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to prevent AVPlayerViewController from updating the lock screen via MPNowPlayingInfoCenter?

here is my problem: I've got an app playing audio files, updating the lockscreen info via MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo, and this part is working fine.

But in an other view, i'm playing a video with AVPlayerViewController and AVPlayer, and when the video starts playing, it's updating the lock screen automatically, with nothing except the video duration.

I didn't find anything about this behaviour in Apple's documentation, I can't find a way to disable it.

So far, I've tried calling UIApplication.sharedApplication().endReceivingRemoteControlEvents() before the video starts playing, and beginReceivingRemoteControlEvents() after. It doesn't work.

Does anyone know a way to prevent this?

like image 362
Jérémy Lapointe Avatar asked Nov 05 '25 02:11

Jérémy Lapointe


1 Answers

Starting with iOS 10 there is a BOOL property in AVPlayerViewController called updatesNowPlayingInfoCenter, that has the default value: YES. Just change it to NO:

//playerController is an instance of AVPlayerViewController
if ([self.playerController respondsToSelector:@selector(setUpdatesNowPlayingInfoCenter:)])
{
    self.playerController.updatesNowPlayingInfoCenter = NO;
}
like image 194
iOS Dev Avatar answered Nov 07 '25 15:11

iOS Dev