Picture-In-Picture not starting with Custom Player

Team,

I am trying to start PictureInPicture for my video from custom player as mentioned in the following link, but I am getting an error

Steps:

Created a player using AVPlayer.

Initiated AVPictureInPictureController with AVPlayerLayer

Added observer on PIP button enable status

When PIP button is tapped executed pipController.startPictureInPicture() statement. PIP is not getting started & getting following error

Project created in Xcode11 & currently using Xcode13.2

Error Domain=AVKitErrorDomain Code=-1001 "Failed to start picture in picture." UserInfo={NSLocalizedDescription=Failed to start picture in picture., NSLocalizedFailureReason=The UIScene for the content source has an activation state other than UISceneActivationStateForegroundActive, which is not allowed.}

I didn't get any solutions online, plz help me on this issue.

FYI: PIP button/mode is working if I use AVPlayerViewController(with default playerItem buttons) instead of AVPlayer & AVPictureInPictureController with custom controls

Thanks in advance.

Adopting Picture in Picture in a Custom Player

Did you have any luck?

Any solution for this? I'm facing the same problem in a SwiftUI app. If I log the activationState is UISceneActivationStateForegroundActive but still PiP is not starting.

Picture-In-Picture not starting with Custom Player
 
 
Q