AVPlayer/AVPlayerItem的缓冲区大小

Osp*_*pho 8 objective-c avaudioplayer ios avplayer

我正在为iOS创建流媒体广播应用程序,我想调整AVPlayer和AVPlayerItem的属性,以便在有损连接条件下让我更可靠地播放.我想增加缓冲区大小.

我能找到的唯一答案就在这里

无论如何要实现这一目标而不去OpenAL?

aru*_*t21 11

在您的观察者方法中添加以下代码.

NSArray *timeRanges = (NSArray *)[change objectForKey:NSKeyValueChangeNewKey];
CMTimeRange timerange = [timeRanges[0] CMTimeRangeValue];

CGFloat smartValue = CMTimeGetSeconds(CMTimeAdd(timerange.start, timerange.duration));
CGFloat duration   = CMTimeGetSeconds(self.player.currentTime);
if(smartValue - duration > 5 || smartValue == duration) {
      // Change the value "5" to your needed secs, its the buffer size.
      // Play the video
}
Run Code Online (Sandbox Code Playgroud)

我已经实施并且运作良好.

参考自:https://stackoverflow.com/a/7730708/2315453