AVPlayerItem with hls url can't step forward/backward

159 Views Asked by At

I have a hls url which plays in my avplayer, but I'm unable to use the [playerItem stepByCount:] method. When I call it, it doesn't do anything.

Also if I call [playerItem canStepBackward]), it always returns false. Is there some other way I have to step forward and backward when I'm playing an hls stream?

My setup is:

AVURLAsset *asset = [AVURLAsset URLAssetWithURL:_URL options:nil];
self.playerItem = [AVPlayerItem playerItemWithAsset:asset];
[self.player replaceCurrentItemWithPlayerItem:self.playerItem];

// later on...
 AVPlayerItem *playerItem = self.player.currentItem;
  if ([playerItem canStepBackward]) {
    if ([self isPlaying]) {
      [self.player pause];
    }
    [playerItem stepByCount:-1];
  }

This all works perfectly when I use mp4s, but with hls canStepBackward always returns false, and if I ignore it and just call [playerItem stepByCount:-1]; anyway, it does nothing.

1

There are 1 best solutions below

0
On BEST ANSWER

If your player's item doesn't support stepping backward/forward you can simply use seek method of AVPlayer for this purpose e.g.:

// Step forward for 1 sec
player.seek(to: CMTime(seconds: player.currentTime().seconds + 1, preferredTimescale: CMTimeScale(NSEC_PER_SEC)))