1

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?

Daniel Saidi
  • 6,079
  • 4
  • 27
  • 29
  • UPDATE: I spent a lot of time investigating, and found that this happens in AVFoundation for some device and system version combinations. All attempts to solve it failed, since AVFoundation does not see anything wrong with the loaded AVItem. However, it IS broken, since playback can never be resumed after this error occurs. I solved it by checking online state for the app and if the loaded item was streaming content from the Internet. If the app is offline and streaming from the Internet, I notify the app that it should pause playback until the app comes back online. Not great, but works. – Daniel Saidi Aug 11 '17 at 17:11

0 Answers0