After the update to Swift 3 I´ve realised that my App takes long time to start playing an audio file from a remote server. In Swift 2.3 this didn't´t happen. I´ve been trying to debug it all day long but I couldn't´t find anything. I´ve been printing the states of the AVPlayer at each moment and I found that it changes from Loading
to Playing
within seconds but then it takes around 20 seconds to really start playing the song.
I am using Jukebox by TeodorPatras
I finally fixed it myself with the next line of code:
player?.playImmediately(atRate: 1.0)
What that line does is, it starts playing immediately without ensuring that the buffer it´s enough to not suffer interruptions. But in my case I prefer that over having to wait for several seconds.
I had the same issues with the devices with iOS 10 only. The solution to support iOS 10 and the old iOS versions is this:
if #available(iOS 10.0, *) {
player?.playImmediately(atRate: 1.0)
} else {
player?.play()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With