This answer is pretty much based on this: fooobar.com/questions/270598 / .... Any loan should go there because it is just a quick transfer.
You are right to assume that when searching far ahead to the part that has not yet been buffered, the player stops. The fact is that it still buffers the data, but does not start automatically when it is ready. So rephrase the related answer to a quick one:
To set up your watchers:
player.currentItem?.addObserver(self, forKeyPath: "playbackBufferEmpty", options: .New, context: nil) player.currentItem?.addObserver(self, forKeyPath: "playbackLikelyToKeepUp", options: .New, context: nil)
Note that in order to be able to observe the values, the passed self must inherit from NSObject .
And for their processing:
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) { guard keyPath != nil else { // a safety precaution super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context) return } switch keyPath! { case "playbackBufferEmpty" : if player.currentItem!.playbackBufferEmpty { print("no buffer") // do something here to inform the user that the file is buffering } case "playbackLikelyToKeepUp" : if player.currentItem!.playbackLikelyToKeepUp { self.player.play() // remove the buffering inidcator if you added it } } }
You can also get information about the available time ranges from the currently playing AVPlayerItem (you can get it through player.currentItem if you did not create it). This allows you to tell the user which parts of the file are ready for use.
As always, you can read a few more documents: AVPlayerItem and AVPlayer
More on key value observation (KVO): here
source share