Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get a callback from AVQueuePlayer/AVPlayerItem when network become active (and is ready to play)?
    text
    copied!<p>I have a <code>AVQueuePlayer</code> 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.</p> <p>For this, I am monitoring </p> <ul> <li><code>AVPlayerItem.status</code></li> <li><code>AVPlayerItem.playbackLikelyToKeepUp</code></li> <li><code>AVPlayer.currentItem</code></li> <li><code>AVPlayer.status</code> </li> <li><code>AVPlayer.error</code></li> </ul> <p>using KVO. For example, if the network connection recovers from temporary error, I expect <code>currentAVPlayerItem.status</code> becomes <code>AVPlayerStatusItemReadyToPlay</code>, which will be reported to my player and I can issue <code>[AVQueuePlayer play]</code> at that point. </p> <p>This mechanism (logic) seems to work some cases, but quite frequently in offline environment, <code>AVPlayerItem.status</code> becomes <code>AVPlayerItemStatusFailed</code>, which item <code>AVQueuePlayer</code> seems to skip automatically. As a result, the queue will end up being empty and no callback can be received from <code>AVPlayerItem</code>. </p> <p>I was hoping that some property in <code>AVPlayer</code> will change when network connection goes bad/recovers, but nothing seems to change (<code>status</code>, <code>error</code> etc). </p> <p>Obviously I can monitor <code>Reachability</code>, but that doesn't work when the app is running in the background.</p> <p>How can I know when the network comes back up and <code>AVQueuePlayer</code> is playable again in this situation?</p> <p>I may be just being a novice around this area. If anybody can give me a general idea how he/she achieves continuous <code>AVQueuePlayer</code> playing experience without being completely stopped by temporary network connection issues, that would be an awesome help as well!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload