我想在AVPlayerViewController中播放本地视频,但是没有找到Done按钮的点击事件。
我的视频可以在 AVPlayerViewController 中播放,但我没有找到下一个按钮、上一个按钮和完成按钮的点击事件。
最佳答案
我这样做是为了从 AVPlayerViewController
获取 Done
按钮点击事件。
首先,创建 Notification.Name
的扩展,如下所示
extension Notification.Name {
static let kAVPlayerViewControllerDismissingNotification = Notification.Name.init("dismissing")
}
现在,创建 AVPlayerViewController
的扩展并覆盖 viewWillDisappear
如下所示
// create an extension of AVPlayerViewController
extension AVPlayerViewController {
// override 'viewWillDisappear'
open override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// now, check that this ViewController is dismissing
if self.isBeingDismissed == false {
return
}
// and then , post a simple notification and observe & handle it, where & when you need to.....
NotificationCenter.default.post(name: .kAVPlayerViewControllerDismissingNotification, object: nil)
}
}
这仅用于处理完成按钮事件的基本功能。
快乐编码...
关于ios - AVPlayerViewController 中的完成按钮单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38565412/