1
votes

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.

1
Why do you expect the playableDuration to remain fixed? The player is reading ahead and playing concurrently. - danh
Can you add some NSLogs to show what bufferedTime is over time, and include it in your question? - Chris McGrath
@danh im sorry i was not clear .. by fluctuating what i really mean is that the duration is reducing .. - Aatish Molasi

1 Answers

0
votes

The duration could be derived from the amount downloaded, whereas the playableDuration is derived from what can be played back.

iOS will only start playback of a mpeg2-ts chunk once the entire chunk has been downloaded.

Suppose you're using 10 second chunks.

Downloaded: 2.2 chunks (22 seconds)
Playable:   2   chunks (20 seconds)
Progress bar = 2 / 2.2 = ~91%

A couple of seconds later....

Downloaded: 2.9 chunks (29 seconds)
Playable:   2   chunks (20 seconds)
Progress bar = 2 / 2.9 = ~69%

Your progress bar has gone backwards...

A couple of seconds later....

Downloaded: 3.1 chunks (31 seconds)
Playable:   3   chunks (30 seconds)
Progress bar = 3 / 3.1 = ~97%

and forwards again...