據我所知,沒有辦法從AVPlayerViewControllerDelegate取回信息。
但由於AVPlayerViewController在那時在內部使用AVPlayer的注入實例......您可以創建AVPlayer的自定義子類來跟蹤該使用情況。
class ViewController: AVPlayerViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
play(stream: URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!)
}
// MARK: - Private
private func play(stream: URL) {
let asset = AVAsset(url: stream)
let playetItem = AVPlayerItem(asset: asset)
player = MyPlayer(playerItem: playetItem)
player?.play()
}
}
class MyPlayer: AVPlayer {
override func seek(to time: CMTime, toleranceBefore: CMTime, toleranceAfter: CMTime, completionHandler: @escaping (Bool) -> Void) {
super.seek(to: time, toleranceBefore: toleranceBefore, toleranceAfter: toleranceAfter, completionHandler: completionHandler)
print("The user did seek to: \(time)")
}
}
這不適用於通過按住Siri Remote的左上或右上按鈕實現的快進和快退。 –