视频播放有一个功能,就像linkedIn视频播放一样。 我正在使用 AVPlayerViewController 播放视频。我面临的问题是,当 AVPlayerviewController 关闭时,我无法检测到关闭按钮事件。 当 AVPlayerController 关闭时,是否有任何观察者或方法会调用?
最佳答案
Swift 3.2
import UIKit
import AVKit
import AVFoundation
class PlayResourcesVC: UIViewController {
//MARK:- Variable Declarations
var video_Url:String = String()
let playerController = AVPlayerViewController()
//MARK:- ViewDidload
override func viewDidLoad() {
super.viewDidLoad()
let player = AVPlayer(url: URL(string: video_Url)!)
playerController.player = player
self.present(playerController, animated: false) {
player.play()
self.playerController.addObserver(self, forKeyPath: #keyPath(UIViewController.view.frame), options: [.old, .new], context: nil)
}
}
override func viewDidDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver(NSNotification.Name.AVPlayerItemDidPlayToEndTime)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//MARK:- All Method
func playerDidFinishPlaying(note: NSNotification) {
self.navigationController?.popViewController(animated: false)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
self.playerController.removeObserver(self, forKeyPath: #keyPath(UIViewController.view.frame))
self.navigationController?.popViewController(animated: false)
}
}
关于ios - 检测 AVPlayerViewController 的关闭按钮的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51760842/