title: AVPlayer shows black screen when playing multiple Videos in Swift3 iOS
body: <p>I am working on <code>Video</code> player based <code>Application</code>, where I have to play multiple
  <code>Videos</code> using <code>AVPlayer</code>. Each <code>video</code> has to play with some <code>CIFilter</code> effect so I am using <code>VideoComposition</code> for that.</p>
  
  <p>My problem is when there is more than one <code>Video</code> in my <code>VideoArray</code> then first <code>Video</code> is playing perfectly with audio, but when it’s coming to the next Video then <code>AVPlayer</code> shows black screen but <code>audio</code> sound of the <code>Video</code> is coming. I am invoking the below common method whenever <code>Video</code> is playing:</p>
  
  <pre><code>private func createPlayerForVideoIndex(index: Int){
  
          guard let videoComposition = videoFilterComposition else { return }
  
          self.player?.pause()
          self.audioPlayer?.pause()
  
          playerLayer?.removeFromSuperlayer()
  
          let video = videoClipsArray.object(at: index) as! VideoFileModel
          playerItem = AVPlayerItem(url:NSURL(fileURLWithPath: video.localFilePath) as URL)
          playerItem?.videoComposition = videoComposition
  
          self.player = AVPlayer(playerItem: playerItem)
  
          playerLayer = AVPlayerLayer(player: player)
  
          playerLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
          playerLayer?.frame = CGRect(x:0, y:67, width:self.view.frame.size.width, height:250)
  
          self.view.layer.addSublayer(playerLayer!)
  
  
  
              if !myScrollView.isDescendant(of: self.view) {
  
                  myScrollView.frame = (playerLayer?.frame)!
                  myScrollView.delegate = self
                  myScrollView.isPagingEnabled = true
                  myScrollView.showsHorizontalScrollIndicator = false
                  myScrollView.showsVerticalScrollIndicator = false
                  myScrollView.backgroundColor = UIColor.clear
  
                  self.view.addSubview(myScrollView)
              }
  
              self.view.bringSubview(toFront: self.pageControl)
  
  
              self.myScrollView.contentSize = CGSize(width:self.myScrollView.frame.size.width * 4,height: self.myScrollView.frame.size.height)
  
              let startSeconds : Int64 = Int64(video.leftRangeValue)
              let targetTime:CMTime = CMTimeMake(startSeconds, 1)
              self.player?.seek(to: targetTime)
  
              let endSeconds : Int64 = Int64(video.rightRangeValue)
              self.player?.currentItem?.forwardPlaybackEndTime = CMTimeMake(endSeconds, 1)
  
              self.player?.volume = videoVolumeSlider.value
  
              self.player?.play()
              self.audioPlayer?.play()
  
              self.player?.rate = video.slowFastMotionRate
  
      }
  </code></pre>
  
  <p>I assume, there should have the problem with above method which is calling every time for each <code>Video</code> (I mean with next video).</p>
  
  <p>Can anyone please suggest me.</p>