title: Background video loop not working in swift
body: <p>I have been created page control, and in that the background videos will be get loaded, the videos is getting played but the loop is not working, <strong>i had refered in stackoverflow</strong>  but i couldn't get the right answer</p>
  
  <p>here is mine code:</p>
  
  <pre><code> override func viewDidLoad() {
      super.viewDidLoad()
      self.pageController.currentPage = 0
      loadVideo(currentPage: 0)
   }
  
  func loadVideo(currentPage: Int) {
  
      DispatchQueue.main.async {
  
      self.videoPath =  Bundle.main.url(forResource: "BoardVideoArray[currentPage]", withExtension: "mp4")
  
      self.player = AVPlayer(url: self.videoPath!)
      self.player?.actionAtItemEnd = .none
      self.player?.isMuted = true
  
     self.playerLayer = AVPlayerLayer(player: self.player)
      self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
      self.playerLayer.zPosition = -1
      }
  
      playerLayer.frame = videoVIew.frame
  
       videoVIew.layer.addSublayer(playerLayer)
       videoVIew.bringSubview(toFront: pageController)
  
      player?.play()
  
      //loop video
      NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: player?.currentItem, queue: nil, using: { (_) in
          DispatchQueue.main.async {
              self.player?.seek(to: kCMTimeZero)
              self.player = AVPlayer(url: self.videoPath!)
              self.player.play()
          }
      })
  
  }
  </code></pre>
  
  <p>I have declared the player and avplayerLayer out of scope</p>
  
  <pre><code>   var player: AVPlayer!
     var playerLayer = AVPlayerLayer()
  </code></pre>
  
  <p>I spend more than 4 hours, but i couldn't found the mistake which i have made.
  <strong>The issue is video is not geting looping</strong></p>