I am buffering a video which is in the m3u8 format and I am setting this url as the contenturl for MPMovieplayerController
I am running a background thread that runs every 0.3 seconds which I use to check the buffered and played duration and perform the check accordingly
if(!mPlaybackProgressTimer)
mPlaybackProgressTimer = [[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(didPlayback:) userInfo:nil repeats:YES] retain];
and in didplayback
..
- (void)didPlayback:(id)sender {
NSTimeInterval totalDuration = [mVideoPlayerController duration];
NSTimeInterval playbackTime = [mVideoPlayerController currentPlaybackTime];
float playbackProgress = 0.0;
if(playbackTime > 0.0 && totalDuration > 0.0)
playbackProgress = playbackTime / totalDuration;
mPercentWatched = round(100 * playbackProgress);
NSTimeInterval bufferedTime = [mVideoPlayerController playableDuration];
float bufferProgress = 0.0;
if(playbackTime > 0.0 && totalDuration > 0.0)
bufferProgress = bufferedTime / totalDuration;
[self setProgress:bufferProgress forProgressType:eProgressTypeBuffer];
[self setProgress:playbackProgress forProgressType:eProgressTypePlay];
}
The problem is that the bufferedTime is fluctuating under certain circumstances :-
- I the m3u8 files divided into separate files for different resolutions and bitrates
- I have an index.m3u8 file which dicides which m3u8 file to serve for what bandwidth
- Of course it does not serve up the whole m3u8 file but individual *.ts files based on how the user will have the best experience without any delay (all this is managed internally)
- Also i have followed all this in accordance with the apple developer guidelines
I'm not sure why the fluctuation is happening but what seems to make sense to me is that .. certain amount of data is buffered but then i think that data may be being discarded (just a theory)
Note: I am using encoding.com to segment the media
UPDATE: Logs
2013-01-14 11:46:57.731 IronStudios[7724:c07] Buffer Progress : 0.139779
2013-01-14 11:46:57.930 IronStudios[7724:c07] Buffer Progress : 0.139779
2013-01-14 11:46:58.130 IronStudios[7724:c07] Buffer Progress : 0.139790
2013-01-14 11:46:58.331 IronStudios[7724:c07] Buffer Progress : 0.139790
2013-01-14 11:46:58.530 IronStudios[7724:c07] Buffer Progress : 0.125042
2013-01-14 11:46:58.730 IronStudios[7724:c07] Buffer Progress : 0.126391
2013-01-14 11:46:58.930 IronStudios[7724:c07] Buffer Progress : 0.124450
2013-01-14 11:46:59.130 IronStudios[7724:c07] Buffer Progress : 0.125799
as you can see the buffer progress is reducing on certain instances.