Search code examples
iosstreambufferavplayerpause

How to force AVPlayer to pause buffering when it is in paused state?


I'm using AVPlayer to play video. I use AVPlayer pause to pause the player. But observing with Charles shows that the stream segments are still being downloaded when the player is in paused state.

I found AVPlayer buffering, pausing notification, and poster frame but they said it was

AVPlayer will buffer the video in several cases, none cleary documented

Is this normal behavior? How to make buffering pause when player pauses?


Solution

  • You need to manage preferredForwardBufferDuration of avplayer currentItem. If you want to stop buffering set value to 1 because if you set it to 0 it will be set up automatically

    self.avPlayer.currentItem.preferredForwardBufferDuration = 1;
    

    From Apple documentation: This property defines the preferred forward buffer duration in seconds. If set to 0, the player will choose an appropriate level of buffering for most use cases. Setting this property to a low value will increase the chance that playback will stall and re-buffer, while setting it to a high value will increase demand on system resources.