Detect if AVPlayerViewController is playing video or buffering and add overlay to the player
<ol>
<li>I have to detect whether the video is in playing or buffering mode.I am loading the video from a URL. I have tried the below code and I am able to track after once the video has started playing, but not when it is in buffering state.  </li>
<li>Also, I want to add an overlay view in my player. I have tried to add the overlay in AVPlayer but when in full screen mode the overlay disappears.  </li>
</ol>

<p>Need some suggestions. Thanks in advance. Below is my code:</p>

<pre><code>    let playerAV = AVPlayerViewController()
    var player = AVPlayer()
    player = AVPlayer(URL: url)
    print(url)
    playerAV.player = player
    playerAV.view.frame = CGRectMake(0, 0,  self.videoView.frame.width,  self.videoView.frame.height)
    self.addChildViewController(playerAV)
    self.videoView.addSubview(playerAV.view)
    playerAV.didMoveToParentViewController(self)
    playerAV.player?.play()
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ChannelDetailViewController.notificationObserver(_:)), name:AVPlayerItemDidPlayToEndTimeNotification , object: player.currentItem)
        _ = UIDevice.beginGeneratingDeviceOrientationNotifications
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ChannelDetailViewController.deviceOrientationDidChange(_:)) , name:
        UIDeviceOrientationDidChangeNotification, object: nil)
    player.addObserver(self, forKeyPath: "rate", options: NSKeyValueObservingOptions.New, context: nil)
  player.addPeriodicTimeObserverForInterval(CMTime(value: 1, timescale: 3), queue: dispatch_get_main_queue()) { [weak self] time in
    self?.handlePlayerStatus(time)
  }

  func handlePlayerStatus(time: CMTime) {
     if player.status == .ReadyToPlay {
     // buffering is finished, the player is ready to play
     print("playing")
  }
  if player.status == .Unknown{
    print("Buffering")
  }
 }

 override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer&lt;Void&gt;) {
    if keyPath == "rate" {
        if let rate = change?[NSKeyValueChangeNewKey] as? Float {
          if player.currentItem!.status == AVPlayerItemStatus.ReadyToPlay{
            if rate != 0 &amp;&amp; player.error == nil {

              print("normal playback")
            }
            else{
              print("playback stopped")
            }

          }else if player.currentItem?.status == AVPlayerItemStatus.Unknown{
            print("test")
          }
        }
    }
    print("you are here")
}
</code></pre>

<p><a href="https://github.com/ghimireprashant/videoControl" rel="noreferrer">check here for project</a></p>