Detect when AVPictureInPictureController shows black screen

Hi all,

I'm using AVPictureInPictureController to show CMSampleBuffers. No problems with that. When the Picture in Picture view/window is active and the phone is locked for long enough (~30 seconds), the Picture in Picture view/window will show black. I've noticed the same happens with Netflix, so I assume there is no way around that.

So when that happens (i.e. Picture in Picture view/window will showing black), I would like to just stop Picture-in-Picture mode. For this, I would need to be able to detect when Picture in Picture view/window will starts showing black pixels.

I've tried listening for UIApplication lifetime events (such as didResignActive. and didMoveToBackground), but as my app is a location-based app that received Location updates in the background, those are not at all an indicator of the black PiP window.

Any suggestions for me on how to handle the PiP window showing a black window upon unlocking the phone?

Did you find any solution? I had to have another buffer enqueued every second to circumvent this symptom.

I found this requiresFlushToResumeDecoding will become true after iPhone lock for a while, before PiP turns black screen. Then as the doc says, flush the bufferLayer will resume it.

So here is the solution for me:

if bufferLayer.requiresFlushToResumeDecoding {
    bufferLayer.flush()
}
if bufferLayer.isReadyForMoreMediaData {
    bufferLayer.enqueue(sampleBuffer)
}
Detect when AVPictureInPictureController shows black screen
 
 
Q