Note that there are some explanatory texts on larger screens.

plurals
  1. POAVPlayer streaming stops in background due to gaps
    primarykey
    data
    text
    <p>I'm attempting to achieve gapless playback due to iOS idling my <code>AVPlayer</code> when the app is in background mode.</p> <p>Before answering, yes, I have the plist modified, audio session properly setup and everything is fine and dandy, however my question, I believe, is different in nature.</p> <p>So, at first I had a method in my class to initialize a new AVPlayer everytime the track URL changed, it worked well but on background not so much, I though that creating a brand new <code>AVPlayer</code> instance every time won't work so I switched to few other paradigms, like <code>replaceCurrentItemWithPlayerItem</code> keeping the AVPlayer instance alive, or even <code>AVQueuePlayer</code>.</p> <p>The problem I'm facing is that, on iOS 6, the moment audio stops, because one track finished and the other one still has to be loaded, the iPhone freezes my app in background. If I get my app in foreground again, playback resumes normally.</p> <p>Since I do not have a continuos stream, but rather individual URLs to hit to begin streaming, I though about using <code>AVPlayerQueue</code> and <code>insertItem:next</code>/<code>advanceToNextItem</code> strategies, attempting to not let any minimal audio interruption to freeze the app in background.</p> <p>The problem however remains, since I have to add the new track in the queue on demand and by the time it buffers iOS already thinks my app is worth stopping. So I need the proper time in the lifecycle of the app to <code>insertItem</code>.</p> <p>I was then trying to listen to this KVO notification:</p> <p><code> [self.player.currentItem addObserver:self forKeyPath:@"playbackBufferFull" options:0 context:MyPlayerItemContext]; </code></p> <p>but it never, ever gets called. The idea was to keep track of the buffer full on the currentItem and append the next one in playlist so AVQueuePlayer <em>might</em> try to prebuffer it.</p> <p>Since <code>playbackBufferFull</code> never gets called another idea is to attempt and grab the current time/duration, calculate where a 90% of the playback might be and fire an event at the appropriate time to begin buffering the next track.</p> <p>Does it sound bad, given that duration properties on objects will and might change based on the progressive incoming data?</p> <p>What other strategies can I take?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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