1

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.

2 Answers 2

1

You can handle network changes with an observer for AVPlayerItemFailedToPlayToEndTimeNotification : AVPlayer : How to handle network interruptions

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your proposal and prompt response. I'll give it a try.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.