I'm using AVPlayer
in my project to play video streaming. My project was written in Swift language.
How can I detect that wrong link is played in AVPlayer
?
I used this:
player.addObserver(self, forKeyPath: "status", options:NSKeyValueObservingOptions(), context: nil)
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if (keyPath == "status") {
let status: AVPlayerStatus = self.playerViewController.player!.status
switch (status) {
case AVPlayerStatus.ReadyToPlay:
print("---------- ReadyToPlay ----------")
break
case AVPlayerStatus.Unknown, AVPlayerStatus.Failed:
print("---------- FAILED ----------")
break
}
}
}
but the result is that it always returns:
---------- ReadyToPlay ----------
Any hints will be helpful. Thanks.