3

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?

Jérémy Lapointe
  • 3,742
  • 1
  • 10
  • 7
  • Update: I didn't find a proper way to fix it (below iOS10), so when the app gets in background, I'm pausing the video (which make it "invisible" to MPNowPlayingInfoCenter), and update nowPlayingInfo with the current song info. – Jérémy Lapointe Sep 16 '16 at 10:59

1 Answers1

5

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;
}
iOS Dev
  • 4,143
  • 5
  • 30
  • 58