使用AVPlayer
时,是否有办法获得playbackLikelyToKeepUp
的进度?我以为我可以查看loadedTimeRanges
看看到目前为止缓冲了多少,但据我所知,playbackLikelyToKeepUp
属性是一些内部预测,并没有提供多少数据的值是真的需要它。
为了正确看待这一点,我尝试做的就是让视频开始播放的进度视图达到100%。
答案 0 :(得分:0)
要在AVPlayer连续播放时开始播放,您可以在playbackLikelyToKeepUp上观察键值更改,如下所示:
$rows = array_values($rows);
然后在您的初始化程序中添加:
let PlayerKeepUp = "playbackLikelyToKeepUp"
var isPlayerReady:Bool = false
最后,追踪玩家何时准备好玩而不会被卡住:
// adding the Observers for Status:
self.player?.currentItem?.addObserver(self, forKeyPath: PlayerKeepUp, options: ([NSKeyValueObservingOptions.New, NSKeyValueObservingOptions.Old]), context: &PlayerItemObserverContext)
最后但并非最不重要的是,请记住删除您的KVO遵守情况,否则您在取消分配播放器时会崩溃:
// MARK: KVO Observing Methods:
override public func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
switch (keyPath, context) {
case (PlayerKeepUp as String, &PlayerItemObserverContext):
if(self.player.currentItem?.playbackLikelyToKeepUp == true) {
self.isPlayerReady = true
// HERE YOU FILL UP YOUR PROGRESS VIEW :-)
self.delegate?.playerReady(self.playerURL! as String)
}
break
default:
super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context)
}
}
希望这会有所帮助: - )