func pictureInPictureControllerWillStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
// note this is first window
if let window = UIApplication.shared.windows.first {
window.addSubview(customView)
// use autoLayout
customView.snp.makeConstraints { (make) -> Void in
make.edges.equalToSuperview()
}
}
}
The shape of the pip window depends on the shape of video. So just change current video to a video with a different shape.
Sample code like:
NSURL *url = [[NSBundle mainBundle] URLForResource:videoName withExtension:@"MP4"];
AVAsset *asset = [AVAsset assetWithURL:url];
AVPlayerItem * item = [[AVPlayerItem alloc] initWithAsset:asset];
[self.pipController.playerLayer.player replaceCurrentItemWithPlayerItem:item];
For more technical exchange you can scan to add my WeChat: