Background audio issues with AVPictureInPictureController

I know that if you want background audio from AVPlayer you need to detatch your AVPlayer from either your AVPlayerViewController or your AVPlayerLayer in addition to having your AVAudioSession configured correctly.

I have that all squared away and background audio is fine until we introduce AVPictureInPictureController or use the PiP behavior baked into AVPlayerViewController.

If you want PiP to behave as expected when you put your app into the background by switching to another app or going to the homescreen you can't perform the detachment operation otherwise the PiP display fails.

On an iPad if PiP is active and you lock your device you continue to get background audio playback. However on an iPhone if PiP is active and you lock the device the audio pauses.

However if PiP is inactive and you lock the device the audio will pause and you have to manually tap play on the lockscreen controls. This is the same between iPad and iPhone devices.

My questions are:

  • Is there a way to keep background-audio playback going when PiP is inactive and the device is locked (iPhone and iPad)
  • Is there a way to keep background-audio playback going when PiP is active and the device is locked? (iPhone)

Replies

Hi jblaker,

Did you ever find a solution to this one? If so please share, It might help me with a similar issue: https://forums.developer.apple.com/forums/thread/745840

Cheers, Joride