Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play AVPlayerItems immediately

I'm using AVPlayer which I connect to an remote URL via an AVPlayerItem. The problem is that I want to play the sound from the URL immediately and don't let the user wait for the AVPlayer to buffer.

The thing is that if the remote URL's asset media is very short then it doesn't buffer for long at all but if the media is a bit longer it takes a while.

Is there a way to skip the buffering process or at least shorten it substantially?

like image 930
nullforlife Avatar asked Oct 16 '25 03:10

nullforlife


1 Answers

Swift 5

You just need to use the automaticallyWaitsToMinimizeStalling property.

player.automaticallyWaitsToMinimizeStalling = false
player.playImmediately(atRate: 1.0)
like image 185
Iaenhaall Avatar answered Oct 18 '25 16:10

Iaenhaall