iOS picture in picture can't start if lazy load

I'm working on video playback app which needs to support PIP(picture in picture). The first problem is once app has instantiated a PIP controller with a player layer, it will auto enter PIP mode if user is playing video and press home button. Is that default behaviour? I can see some statement in Apple API document https://developer.apple.com/library/prerelease/ios/documentation/WindowsViews/Conceptual/AdoptingMultitaskingOniPad/QuickStartForPictureInPicture.html but I want to confirm.

If you support PiP this way but want to opt out of PiP for a particular video, do not associate that video’s AVPlayerLayer with an AVPictureInPictureController object. As soon as you instantiate a Picture in Picture controller with a player layer, you make the player layer’s video eligible for PiP; the way to opt out is to not perform that instantiation.

Another thing I find is if app initials PIP controller as soon as player view created(AVPlayerLayer as layer class), the video not start to play the PIP controller can function well, but if instantiate a PIP controller when video is playing and user click PIP button. The pictureInPicturePossible value will be no and can't start PIP. And the delegate method won't be invoked.

- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController failedToStartPictureInPictureWithError:(NSError *)error;

Does anyone have idea about this? Thanks

Answers


Yes, if your app instantiates AVPictureInPictureController with the AVPlayerLayer at the beginning, it will automatically go to picture-in-picture mode when the user presses the Home button. But this is only possible if you enable 'Allow Audio,Airplay and Picture in Picture' in 'Background Modes' under your App's Capabilities view.

Also for Picture in picture behavior to be consistent, we have to initialize at beginning and not in between. It's handy to implement the delegate methods to understand when the player is going in and out of PiP mode.

To disallow a video from having PiP mode and if you use AVKit, just set its allowsPictureInPicturePlayback to NO.


Need Your Help

How to interleave two lists in Haskell in one line with higher-order functions

haskell

I want to take two lists and return the interleaved list using one line of code.

How would I know when to insert, delete or update based off a C# list?

sql insert listbox sql-delete

Let's say that I have three tables "Person", "Area", and "Person_Area". Each person can work in many areas and each area can have many people in them. "person_Area" is a bridge table that contains