我有一个从avqueueplayer玩的网址列表。我正在加载曲目和可播放键,并在每个项目完成播放后逐个将AVplayeritems添加到队列播放器中。
我使用以下代码处理播放器的缓冲状态
for (NSValue *time in player.currentItem.loadedTimeRanges)
{
CMTimeRange range;
[time getValue:&range];
CGFloat seekTimeInSeconds = [self playerTimeToSeek];
CMTime timeSeek = CMTimeMakeWithSeconds(seekTimeInSeconds, NSEC_PER_SEC);
bufferReady = CMTimeRangeContainsTime(range, timeSeek);
NSLog(@"%f , %f ",CMTimeGetSeconds(range.start), CMTimeGetSeconds(range.duration));
if (CMTimeGetSeconds(range.duration)==0)
{
[self.player seekToTime: CMTimeMakeWithSeconds(seekTimeInSeconds, NSEC_PER_SEC) ];
}
if ((seekTimeInSeconds) >= CMTimeGetSeconds(self.player.currentItem.duration)) //
{
bufferReady = YES;
}
if (bufferReady)
{
//if (self.bufferEmptyOccured || change|| self.bufferNeedsUpdate)
{
[self manageBufferSufficientState];
self.bufferNeedsUpdate = NO;
}
self.bufferEmptyOccured = NO;
break;
}
}
if (!player.currentItem && self.nowPlayingAudioRecord[@"AudioItem"])
{
{
bufferReady = YES;
//if (self.bufferEmptyOccured||change || self.bufferNeedsUpdate)
{
[self manageBufferSufficientState];
self.bufferNeedsUpdate = NO;
}
self.bufferEmptyOccured = NO;
}
}
if (self.nowPlayingAudioRecord &&! self.nowPlayingAudioRecord[@"AudioItem"])
{
bufferReady = NO;
}
if (!bufferReady)
{
//if (!self.bufferEmptyOccured || change || self.bufferNeedsUpdate)
{
[self manageBufferEmptyState];
if (self.bufferNeedsUpdate)
{
self.bufferNeedsUpdate = NO;
}
}
self.bufferEmptyOccured = YES;
}
});
和' playertimetoseek'方法确定在缓冲区准备好的情况下玩家必须寻找的时间。这是因为我的每个网址都需要在预定义的时间播放才能播放。 通过使用计时器验证缓冲状态
,每0.6秒定期调用此方法一次它运行正常,但出于某种原因,在音频的持续时间内,一些网址永远不会被缓冲(每个音频的持续时间为10-20秒),并且日志打印为
2013-11-21 18:51:02.404 myapp [523:1000b] 1.009063,0.000000
2013-11-21 18:51:03.003 myapp [523:1000b] 1.608808,0.000000
2013-11-21 18:51:03.606 myapp [523:1000b] 2.208690,0.000000
2013-11-21 18:51:04.203 myapp [523:1000b] 2.811525,0.000000
2013-11-21 18:51:04.804 myapp [523:1000b] 3.408591,0.000000
2013-11-21 18:51:05.403 myapp [523:1000b] 4.009229,0.000000
2013-11-21 18:51:06.003 myapp [523:1000b] 4.608602,0.000000
2013-11-21 18:51:06.604 myapp [523:1000b] 5.208743,0.000000
2013-11-21 18:51:07.204 myapp [523:1000b] 5.809145,0.000000
2013-11-21 18:51:07.803 myapp [523:1000b] 6.409183,0.000000
2013-11-21 18:51:08.404 myapp [523:1000b] 7.008626,0.000000
2013-11-21 18:51:09.003 myapp [523:1000b] 7.609262,0.000000
2013-11-21 18:51:09.604 myapp [523:1000b] 8.208768,0.000000
2013-11-21 18:51:10.203 myapp [523:1000b] 8.809213,0.000000
2013-11-21 18:51:10.804 myapp [523:1000b] 9.408639,0.000001
2013-11-21 18:51:11.404 myapp [523:1000b] 9.408639,0.000001
2013-11-21 18:51:12007 myapp [523:1000b] 10.579592,0.000000
请注意,我的网络很不错,音频比特率为128Kbps。为什么会发生这种情况?这有什么特别的原因吗?
编辑::在其他一些案例中,日志如下:
2013-11-21 20:53:33.970 myApp [819:605b] 2.358489,0.000000
2013-11-21 20:53:34.570 myApp [819:605b] 2.958184,0.000000
2013-11-21 20:53:35.170 myApp [819:605b] 3.558097,0.000000
2013-11-21 20:53:35.770 myApp [819:605b] 4.158253,0.000000
2013-11-21 20:53:36.371 myApp [819:605b] 4.758271,0.000000
2013-11-21 20:53:36.970 myApp [819:605b] 5.358620,0.000000
2013-11-21 20:53:37.570 myApp [819:605b] 5.958164,0.000000
2013-11-21 20:53:38.170 myApp [819:605b] 6.558318,0.000000
2013-11-21 20:53:38.770 myApp [819:605b] 7.158033,0.000000
2013-11-21 20:53:39.371 myApp [819:605b] 7.758199,0.000009
2013-11-21 20:53:39.971 myApp [819:605b] 7.758199,0.417969
2013-11-21 20:53:40.571 myApp [819:605b] 7.758199,9.247356
2013-11-21 20:53:41.171 myApp [819:605b] 9.978836,19.095449
2013-11-21 20:53:41.770 myApp [819:605b] 9.978836,19.095449
2013-11-21 20:53:42.371 myApp [819:605b] 9.978836,19.095449
2013-11-21 20:53:42.971 myApp [819:605b] 9.978836,19.095449
2013-11-21 20:53:43.573 myApp [819:605b] 9.978836,19.095449
2013-11-21 20:53:44.171 myApp [819:605b] 9.978836,19.095449
这是怎么发生的。它没有缓冲任何东西,直到20:53:39.971并且在0.6秒内缓冲几乎所有东西。缓冲是如何工作的?