Chris K. Chris K. - 1 year ago 415
Swift Question

Swift 2.2 AVPlayer error handling

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

Any hints will be helpful. Thanks.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download