Reputation: 258
I'm trying to catch an error on AVPlayer (Swift 2.2) when streaming url is server down with no success.
I did add status and rate observers but their respond is not the expected. It states that player status is ready to play.
playerItem = AVPlayerItem(URL: NSURL(string: streaminglink)!)
playerItem.addObserver(self, forKeyPath: "timedMetadata", options: .New, context: nil)
player = AVPlayer(playerItem:playerItem)
player.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions(), context: nil)
player.addObserver(self, forKeyPath: "rate", options: .New, context: nil)
player.rate = 1.0
player.play()
Any hints will be helpful. Thanks.
Upvotes: 1
Views: 3700
Reputation: 258
Actually, i removed the rate observer and instead of status observer on player, i applied it in playerItem
playerItem.addObserver(self, forKeyPath: "status", options: NSKeyValueObservingOptions(), context: nil)
Now, i get when my streaming is online, or server is currently down.
Upvotes: 0
Reputation: 783
You can handle network changes with an observer for AVPlayerItemFailedToPlayToEndTimeNotification : AVPlayer : How to handle network interruptions
Upvotes: 1