I use AVPlayer for streaming mp3 file from the internet and it works really slow. Using profiler I found out, that it downloads entire file at first, and then starts playing. Is there any workaround for this?
Right now, I'm using this code
if let player = player {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
let item = AVPlayerItem(url: url)
player.replaceCurrentItem(with: item)
} else {
player = AVPlayer(url: url)
}
player?.play()
Things I've tried:
All the time the result is downloading a whole audio file and only then start of playing.
Please note, the issue is - player starts to play ONLY after the whole file was downloaded, while I want it to stream mp3.
To play immediately you can try to set
player.automaticallyWaitsToMinimizeStalling = false
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