title: Swift: Detect video end
body: <p>I have to play some videos in my swift application. The video is working perfectly but I want to detect when the video is ended. I searched about that then I found that the <code>NotificationCenter</code> is the solution for that. I used this code but my application crash at the end of the video. </p>
  
  <p>This is my code:</p>
  
  <pre><code>func playVideo(url: NSURL){
  let player = AVPlayer(url: url as URL)
  
          NotificationCenter.default.addObserver(self, selector: Selector(("playerDidFinishPlaying")), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
  player.play()
  }
  
  func playerDidFinishPlaying(note: NSNotification) {
          print("Video Finished")
      }
  </code></pre>
  
  <p>The error is: </p>
  
  <pre><code>[myApp.myViewController playerDidFinishPlaying]: unrecognized selector sent to instance 0x79669740
  </code></pre>
  
  <p>Any help please?</p>