I have a AVQueuePlayer
based audio streaming player that needs to run in the background. The player needs to continue running until it finishes playing all the list. Of course it is going to have to pause if the network connection becomes bad, but it should automatically resume when the network connection comes back.
For this, I am monitoring
AVPlayerItem.status
AVPlayerItem.playbackLikelyToKeepUp
AVPlayer.currentItem
AVPlayer.status
AVPlayer.error
using KVO. For example, if the network connection recovers from temporary error, I expect currentAVPlayerItem.status
becomes AVPlayerStatusItemReadyToPlay
, which will be reported to my player and I can issue [AVQueuePlayer play]
at that point.
This mechanism (logic) seems to work some cases, but quite frequently in offline environment, AVPlayerItem.status
becomes AVPlayerItemStatusFailed
, which item AVQueuePlayer
seems to skip automatically. As a result, the queue will end up being empty and no callback can be received from AVPlayerItem
.
I was hoping that some property in AVPlayer
will change when network connection goes bad/recovers, but nothing seems to change (status
, error
etc).
Obviously I can monitor Reachability
, but that doesn't work when the app is running in the background.
How can I know when the network comes back up and AVQueuePlayer
is playable again in this situation?
I may be just being a novice around this area. If anybody can give me a general idea how he/she achieves continuous AVQueuePlayer
playing experience without being completely stopped by temporary network connection issues, that would be an awesome help as well!