访问AVPictureInPictureController的委托回调以获取WKWebView

时间:2017-10-09 14:57:32

标签: ios swift delegates wkwebview picture-in-picture

我需要能够访问pictureInPictureControllerDidStopPictureInPicture(_:)的原生AVPictureInPictureController的委托回调方法WKWebViewAVPictureInPictureController没有像旧版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

2 个答案:

答案 0 :(得分:1)

如果您对AVPictureInPictureController有任何访问权限,则只需设置其委托并实施回调即可

class MyWebView: WKWebView {

    self.myPictureInPictureController.delegate = self

}

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

答案 1 :(得分:0)

我能够发现有一个名为PGPictureInPictureProxyPictureInPictureActiveChangedNotification的通知,当视频移动到画中画时调用,然后在画中画关闭时再调用。我确定它可以在任何时候被更改或删除,但它现在似乎正在起作用。