請問一下 最近碰到avplayer loading時機的問題, 目前想做到當在進行
緩衝的時候, 顯示loading的動畫
目前看到的做法是註冊監聽
self.playerItem?.addObserver(self, forKeyPath: "playbackBufferEmpty", options: .new, context: nil)
self.playerItem?.addObserver(self, forKeyPath: "playbackLikelyToKeepUp", options: .new, context: nil)
self.playerItem?.addObserver(self, forKeyPath: "playbackBufferFull", options: .new, context: nil)
override func observeValue()
if keyPath == "playbackBufferEmpty" {
if let item = playerItem {
if item.isPlaybackBufferEmpty {
self.download.startAnimating()
}
}
} else if keyPath == "playbackLikelyToKeepUp" {
if let item = playerItem {
if item.isPlaybackLikelyToKeepUp {
self.download.stopAnimating()
}
}
} else if keyPath == "playbackBufferFull" {
if let item = playerItem {
if item.isPlaybackBufferFull {
self.download.stopAnimating()
}
}
}
但是發現 loading 動畫停止的時候 並不會 馬上播放, 要等好幾秒
要怎麼才能做到當loading動畫停止"馬上"播放