ios - AVPlayerViewController 中的完成按钮单击事件

标签 ios objective-c avplayer avplayerviewcontroller

我想在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/

相关文章:

ios - NSDate 因连续操作而崩溃

ios - iOS:使用AES-128加密播放离线HLS

ios - 向下滑动动画以显示错误

objective-c - uibutton在uitableview的uitableviewcell中设置可见

iOS/Obj-C - didReceiveRemoteNotification 语句没有触发?

swift - AVPlayer 无法加载通过 xcode 重新运行应用程序后保存的 .mov 文件

ios - AVPlayer-自动质量更改-多个URL

ios - 更新到 iOS 9 错误 : i386 Unsupported architecture

iphone - UITableView didSelectRowAtIndexPath 返回错误的行索引 (iOS7)

iphone - 将数组保存到包含自定义对象 iPhone 的 Plist 文件