Emily
Emily

Reputation: 11

preload HLS streaming for a list of playerItem

I'm trying to preload the first second of a list of playerItems to prevent delay at beginning. I'm using preferredForwardBufferDuration to preload.

Here is a snippet for preload setup:

//setup repload in advance
VURLAsset *asset = [AVURLAsset assetWithURL:m3u8URL];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
playerItem.preferredForwardBufferDuration = 1;
AVPlayer *player = [[AVPlayer alloc] init];
_playerLayer.player = player;
player.replaceCurrentItemWithPlayerItem(playerItem)

// as soon as playback begins, reset it to 0 _item.preferredForwardBufferDuration = 0;

I have two questions:

  1. I noticed that it takes about 1-3 seconds (great wifi) for playerItem status change from AVPlayerItemStatusUnknown to AVPlayerItemStatusReadyToPlay after the setup. So if I tap to play within 1 second after the preload setup, it will have to wait until status changes to ready. Why it's taking that much time and what's causing the status change? Prefetching the first 1 second under great wifi shouldn't take that long.
  2. I would like to preload the first second of a list of playerItems. Is it possible to use the above method? Or if I can use AVAssetResourceLoader?

Upvotes: 1

Views: 1987

Answers (1)

Ilia
Ilia

Reputation: 1444

Speeding up playback has several variables to deal with. Take a look on this session https://developer.apple.com/videos/play/wwdc2016/503/ it contains section "Speeding up HTTP Live Streaming" which may be helpful.

Loading time may contains several components e.g. master playlist is too long and it takes time to load it and parse (in this case recommended to setup http compression with gzip on web server) or FairPlay stream encrypted before starts playing. If your stream is video you may also tweak initial quality of video.

Upvotes: 1

Related Questions