I'm building a music streaming app using AVPlayer. Everything is working fine, music keeps playing in the background, etc. My problem is when I simulate connection loss on the phone (switch cellular data off, wait for the stream to stop and then switch back) it will take about 2 mins for the app to fill the buffer even if there's a 3G network present (I can surf the web meanwhile).
Everything is working in simulator, but not on device. If I wait 2 mins I'll get a proper playbackLikelyToKeepUp notification, and from that on everything is fine, but that rebuffering should be just a few seconds. It's ok when I simulate low bandwidth by turning off bandwidth control on my router, but when I simulate carrier change by switching off cellular data and switch it back its that long.
I'm calling beginInterruption on "playbackBufferEmpty" and call endInterruption on "playbackLikelyToKeepUp". The main problem is "playbackLikelyToKeepUp" arrives way too late.
- (void)beginInterruption {
self.backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
}
- (void)endInterruptionWithFlags:(NSUInteger)flags {
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskIdentifier];
self.backgroundTaskIdentifier = UIBackgroundTaskInvalid;
if(self.interrupted) [self play];
self.interrupted = NO;
}
Any ideas? I've spent my whole day with this issue, googled everything but I'm stuck. Thanks in advance.