When using AVPlayer to play audio from an url it will discontinue to play when for example disconnecting from wifi.
[pl
0xced's answer for Swift 3/4:
var playerItem: AVPlayerItem?
var player: AVPlayer?
func instantiatePlayer(_ url: URL) {
self.playerItem = AVPlayerItem(url: url)
self.player = AVPlayer(playerItem: self.playerItem)
NotificationCenter.default.addObserver(self, selector: #selector(playerItemFailedToPlay(_:)), name: NSNotification.Name.AVPlayerItemFailedToPlayToEndTime, object: nil)
}
func playerItemFailedToPlay(_ notification: Notification) {
let error = notification.userInfo?[AVPlayerItemFailedToPlayToEndTimeErrorKey] as? Error
}