问题描述
iOS AVPlayer的默认最大和最小缓冲区大小是多少?如何增加其大小以用于mp3流?谢谢
What is the default maximum and minimum buffer size of iOS AVPlayer? How to increasing its size for mp3 streaming? thank you
推荐答案
如果您的缓冲区大小表示回放缓冲区,那么我认为该大小没有记载.
If your buffer size means playback buffer, then I believe this size is undocumented.
此行为由AVFoundation提供,引用在 AVFoundation播放中的高级
This behaviour is provided by AVFoundation, quoted on Advances in AVFoundation Playback
在这种情况下,我们将进入等待状态并重新缓冲,直到我们有足够的机会进行游戏为止.
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.
如果您想控制缓冲,请返回主题.您可以观察AVPlayerItem
的loadedTimeRanges
属性.
Back to the topic, if you would like to take control of buffering.You can observe AVPlayerItem
's loadedTimeRanges
property.
下面的代码段具有5秒的缓冲时间:
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];
}
}
}
}
}
这篇关于AVPlayer的默认缓冲区大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!