When AVPlayer plays an asset that comes from network stream, it pauses when reaches the end of downloaded content.
So, my question is, how to know, that it stopped because of bad network? And how to play it after it downloads, let’s say, next 10 seconds of asset?
You can add an observer to when the AVPlayer gets empty buffer:
And an observer so you can know when the AVPlayer buffered enough to keep up:
Then just check for that in your KVO callback:
For swift
Swift 4 changes the way of KVO. Instead of add observer and function separately, we use a closure(block) in one place.