Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- player.currentItem!.addObserver(self, forKeyPath: "status", options: .New, context: nil)
- override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
- if (keyPath == "status") {
- if let currentItem = self.player?.currentItem {
- let status = currentItem.status
- if (status == .ReadyToPlay) {
- self.play()
- }
- }
- }
- }
- }
- var isObservingCurrentItem = false
- if currentItem = player.currentItem where isObservingCurrentItem {
- currentItem.removeObserver(self, forKeyPath:"status")
- }
- player.currentItem!.addObserver(self, forKeyPath: "status", options: .New, context: nil)
- isObservingCurrentItem = true
- override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
- if let object = object,
- keyPath = keyPath,
- currentItem = self.player?.currentItem,
- status = currentItem.status
- where status == .ReadyToPlay {
- self.play()
- object.removeObserver(self, forKeyPath:keyPath)
- isObservingCurrentItem = false
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement