跟踪tvos中的快进/快退

时间:2017-03-29 10:25:54

标签: objective-c avplayer tvos avplayerviewcontroller

Apple的tvos AVPlayerViewController允许用户通过按下siri遥控器的最右侧/最左端来快进/快退。是否有任何委托方法来跟踪此情况。我确实遇到过以下方法,但它只能用于跟踪拖放搜索或向前搜索10秒。有没有其他方法可以跟踪快进,而无法跟踪avplayeritems currentTime属性?

- (void)playerViewController:(AVPlayerViewController *)playerViewController
willResumePlaybackAfterUserNavigatedFromTime:(CMTime)oldTime
                      toTime:(CMTime)targetTime

1 个答案:

答案 0 :(得分:0)

据我所知,无法从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)")
    }
}