ios – I am making an attempt to do a Image in Image operate, however after I init a PIP controller, it at all times return nil, I cannot discover the explanation

[ad_1]

I primarily add a AVPlayerLayer to self.view, and when click on a button, attempt to begin pip play, however pip controller at all times be nil, it is unusual.

var myPlayer: AVPlayerLayer?
var pipController: AVPictureInPictureController?


playItem = AVPlayerItem(asset: asset)
participant = AVPlayer(playerItem: playItem!)
myplayer = AVPlayerLayer.init(participant: participant)
myplayer!.body = CGRect.init(x: 0, y: 100, width: UIScreen.major.bounds.measurement.width, top: 300)
myplayer!.videoGravity = .resizeAspect
view.layer.addSublayer(myplayer!)


@IBAction func pipAction(_ sender: Any) {
     if AVPictureInPictureController.isPictureInPictureSupported() == true {
         //why pipController is nil ???
         pipController = AVPictureInPictureController(playerLayer: myPlayer!)
         pipController?.delegate = self
         if pipController!.isPictureInPicturePossible {
             if pipController!.isPictureInPictureActive {
                 pipController?.stopPictureInPicture()
             } else {
                 pipController?.startPictureInPicture()
             }
         }
     } else {
         print("not supported")
     }
 }

after I debug, I discover myPlayer will not be nil

(lldb) po myplayer
▿ Elective<AVPlayerLayer>
  - some : <AVPlayerLayer:0x2827b87b0; place = CGPoint (207 250); bounds = CGRect (0 0; 414 300); sublayers = (<AVPlayerLayerIntermediateLayer: 0x2827b87e0>); allowsGroupOpacity = YES; >

(lldb) po myplayer!
<AVPlayerLayer:0x2827b87b0; place = CGPoint (207 250); bounds = CGRect (0 0; 414 300); sublayers = (<AVPlayerLayerIntermediateLayer: 0x2827b87e0>); allowsGroupOpacity = YES; >

hope your resolution!!!

[ad_2]

Leave a Reply