Search code examples
swiftswift3avfoundationavplayeravplayeritem

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?


Solution

  • Swift 5

    You just need to use the automaticallyWaitsToMinimizeStalling property.

    player.automaticallyWaitsToMinimizeStalling = false
    player.playImmediately(atRate: 1.0)