AVPictureInPictureController

AVPictureInPictureController

我需要能够访问委托回调方法pictureInPictureControllerDidStopPictureInPicture(_:)的本机AVPictureInPictureControllerWKWebViewAVPictureInPictureController不像旧的MPMoviePlayerViewController那样具有全局通知事件,并且我无法创建自己的AVPictureInPictureController实例以与Web视图一起使用以访问委托回调。我找不到有关如何挂接到AVPictureInPictureController对象的内部WKWebView的文档。我希望至少可以通过某种方式使用KVO。

https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/AdoptingMultitaskingOniPad/QuickStartForPictureInPicture.html

WebKit框架提供了WKWebView类,该类支持iOS 9中的画中画。

https://developer.apple.com/documentation/avkit/avpictureinpicturecontrollerdelegate/1614717-pictureinpicturecontrollerdidsto

最佳答案

如果您有权访问AVPictureInPictureController,则只需设置它的委托并实现回调

class MyWebView: WKWebView {

    self.myPictureInPictureController.delegate = self

}

extension MyWebView: AVPictureInPictureControllerDelegate {
    func pictureInPictureControllerDidStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
        //code
    }
}

09-28 10:08