I have a list of urls to be played from an avqueueplayer . I am loading the tracks and playable keys and adding the AVplayeritems into the Queue player one by one after each Item has finished playing.
Iam handling the buffering states of the player using the following code
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;
}
});
and 'playertimetoseek' method determines the time to which the player has to seek in case buffer is ready. This is because each of my urls need to be played at a predefined time to be played. This method is called regularly once every 0.6 secs by using a timer to verify the buffering status
It works well normally , but for some reason , a few urls never get buffered ( each audio is of 10-20 sec duration) within the duration of the audio and the log gets printed as
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:12.007 myapp[523:1000b] 10.579592 , 0.000000
Note that I am on a decent network and the audio bitrate is 128Kbps. Why could this be happening ? Is there any specific reason for this ?
EDIT:: In a few other cases the logs are as below :
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
How does this happen . It hasn't buffered anything until 20:53:39.971 and buffered almost everything within 0.6 seconds . How exactly does buffering work ?