Done button click event in AVPlayerViewController

前端 未结 9 860
广开言路
广开言路 2020-12-03 17:40

I want to play local video in AVPlayerViewController but did not find click event of Done button.

My video is able to play in AVPlayerViewController but I did not fi

9条回答
  •  不思量自难忘°
    2020-12-03 17:51


    I've done this to get Done button click event from AVPlayerViewController.

    First of all, Create an extension of Notification.Name like bellow

    extension Notification.Name {
    static let kAVPlayerViewControllerDismissingNotification = Notification.Name.init("dismissing")
    }
    

    Now, Create an extension of AVPlayerViewController and override viewWillDisappear like bellow

    // 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)
        }
    }
    

    THIS IS FOR ONLY BASIC FUNCTIONALITY THAT HANDLES DONE BUTTON'S EVENT.

    happy coding...

提交回复
热议问题