Done button click event in AVPlayerViewController

前端 未结 9 854
广开言路
广开言路 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:52

    The easiest solution for me was to subclass AVPlayerViewController and add simple completion block to it.

    class MYVideoController: AVPlayerViewController {
    
      typealias DissmissBlock = () -> Void
      var onDismiss: DissmissBlock?
    
      override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        if isBeingDismissed {
          onDismiss?()
        }
      }
    }
    

    Usage

    ...
    let avPlayerViewController = MYVideoController()
    avPlayerViewController.onDismiss = { [weak self] in 
        print("dismiss")
    }
    

提交回复
热议问题