Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer seekToTime: doesn't use buffer

I am developing an application for playing video using HTTP Live Streaming technology.
For this I use AVPlayer which init as follows:

[[AVPlayer alloc] initWithURL:[NSURL URLWithString:VIDEO_URL]];

Then I check the state of the buffer using self.player.currentItem.loadedTimeRanges and display this range on my custom view.

The problem is that when rewinding in an area that is loaded by [self.player seekToTime:timeToSeek toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];, loads the video starts just as if it was not in the buffer.

like image 790
Pavel Rudkouski Avatar asked Oct 05 '22 01:10

Pavel Rudkouski


1 Answers

First of all, my answer assumes that you are using HTTP Live Streaming for a static m3u8 list, otherwise seeking within the video will not make much sense.

Possible Cause

HTTP Live Streaming uses an m3u style playlist which embeds sub playlists. Each sub-playlist shows different video quality and the AVPlayer chooses which one to use according to the network speed.

But, according to Apple's documentation, when the player initially starts playing it first chooses the first sub-playlist and only after a couple of ts files were played it chooses the appropriate sub-playlist as described above.

So it could be that when you seek to a certain time, the player first tries to play the first sub-list which is not cached.

Suggested Solution

Try the following:

  1. Change the m3u8 stream to have only one sub-stream.
  2. Use a value other than kCMTimeZero for the tolerance, i.e.CMTimeMake(30, 60)
  3. Monitor the network calls to see what exactly it is that the player downloads and when, you could use Charles proxy for example.
like image 60
Tom Susel Avatar answered Oct 13 '22 12:10

Tom Susel