I am using the AVPlayer
class to stream remote (and really long) MP3 files by loading AVPlayerItem
instances into the player:
let player = AVPlayer(playerItem: myAVPlayerItemInstance)
I listen to KVO changes and system notifications, to detect whenever buffering begins or ends and when the item buffer becomes empty.
If I play a file while online, I can listen to it without any lag, even while buffering. I can jump back and forth, use a slider to jump to any position in the stream etc. Everything works great.
If I start playing the file, then quickly go offline after only buffering a small part of the entire file, I can drag the time slider beyond the buffered content. The player will then pause, since there is no more content to be played. If I then go online, the audio automatically starts playing again.
So far, so good.
However, if I start playing the file, then quickly go offline after buffering a small part of the entire file, then let the player play to the end of the buffered content, strange things happen. The player will of course pause, since there is no more content to be played. However, if I now go online, the audio player will not play any more content from the loaded item. I tell the player to play, and it sets its playback rate properly, but the item will not play.
Any ideas why this is happening?