Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. player.currentItem!.addObserver(self, forKeyPath: "status", options: .New, context: nil)
  2.  
  3. override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
  4. if (keyPath == "status") {
  5. if let currentItem = self.player?.currentItem {
  6. let status = currentItem.status
  7. if (status == .ReadyToPlay) {
  8. self.play()
  9. }
  10. }
  11. }
  12. }
  13. }
  14.  
  15. var isObservingCurrentItem = false
  16.  
  17. if currentItem = player.currentItem where isObservingCurrentItem {
  18. currentItem.removeObserver(self, forKeyPath:"status")
  19. }
  20.  
  21. player.currentItem!.addObserver(self, forKeyPath: "status", options: .New, context: nil)
  22. isObservingCurrentItem = true
  23.  
  24. override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
  25.  
  26. if let object = object,
  27. keyPath = keyPath,
  28. currentItem = self.player?.currentItem,
  29. status = currentItem.status
  30. where status == .ReadyToPlay {
  31. self.play()
  32. object.removeObserver(self, forKeyPath:keyPath)
  33. isObservingCurrentItem = false
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement