问题
What is the default maximum and minimum buffer size of iOS AVPlayer? How to increasing its size for mp3 streaming? thank you
回答1:
If your buffer size means playback buffer, then I believe this size is undocumented.
This behaviour is provided by AVFoundation, quoted on Advances in AVFoundation Playback
And we see that playback starts but then we quickly run into a stall because we didn't have enough buffer to play to the end.
In that case, we'll go into the waiting state and re-buffer until we have enough to play through.
They just mentioned enough not the exact time or size, it make sense that is a dynamic unit of measurement according to current network situation, but who knows.
Back to the topic, if you would like to take control of buffering.
You can observe AVPlayerItem
's loadedTimeRanges
property.
below code snippet had 5 seconds buffer time:
if ([keyPath isEqualToString:@"loadedTimeRanges"]) {
NSArray *timeRanges = (NSArray *)[change objectForKey:NSKeyValueChangeNewKey];
if (timeRanges && [timeRanges count]) {
CMTimeRange timerange = [[timeRanges objectAtIndex:0] CMTimeRangeValue];
if (self.audioPlayer.rate == 0 && !pauseReasonForced) {
CMTime bufferdTime = CMTimeAdd(timerange.start, timerange.duration);
CMTime milestone = CMTimeAdd(self.audioPlayer.currentTime, CMTimeMakeWithSeconds(5.0f, timerange.duration.timescale));
if (CMTIME_COMPARE_INLINE(bufferdTime , >, milestone) && self.audioPlayer.currentItem.status == AVPlayerItemStatusReadyToPlay && !interruptedWhilePlaying && !routeChangedWhilePlaying) {
if (![self isPlaying]) {
[self.audioPlayer play];
}
}
}
}
}
来源:https://stackoverflow.com/questions/25397719/what-is-the-default-buffer-size-of-avplayer