How to make a AVPlayerViewController go to fullscreen programmatically?

前端 未结 9 1131
既然无缘
既然无缘 2020-12-29 20:12

I\'m trying to make a AVPlayerViewController go to full screen mode programmatically, coming from \"embedded\" mode, however this does not appear to be possible with the pub

9条回答
  •  粉色の甜心
    2020-12-29 20:50

    For an 'embedded' AVPlayerViewController instance, it is quite easy to programmatically have it start playback in full screen mode, and without hacking anything (calling private methods). You just need to set its entersFullScreenWhenPlaybackBegins property to true.

    You need to add the controller as a child VC to the main VC, and that's basically it. In viewDidAppear(_:) you need to call play() method on the controller's player property - playback will be automatically started in fullscreen.

    It's often best to check Apple sample code for these kind of tricky APIs; I think this one might be useful for a lot of AVPlayer use cases: Using AVKit in iOS.

提交回复
热议问题