0

I have a couple of videos that need to be played in a loop.

    let player = AVQueuePlayer(items: items)
    let playerLayer = AVPlayerLayer(player: player)
    playerLayer.frame = view.bounds
    playerLayer.videoGravity = .resizeAspectFill
    view.layer.addSublayer(playerLayer)
    player.play()

I am trying to achieve by notification but I am getting the proper update.

   NotificationCenter.default.addObserver(forName: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: .main) {[weak self] (notification) in
        print("Notification: \(notification.object)")
    }

Also tried to use PlayerLooper but it's playing the single item in loop.

    queuePlayer = AVQueuePlayer(items: items)
    playerLooper = AVPlayerLooper(player: queuePlayer!, templateItem: items[0])
    let playerLayer = AVPlayerLayer(player: queuePlayer!)
    playerLayer.frame = view.bounds
    playerLayer.videoGravity = .resizeAspectFill
    view.layer.addSublayer(playerLayer)
    queuePlayer?.play()
Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
  • Does this answer your question? [Using AVPlayerLooper to loop through multiple videos](https://stackoverflow.com/questions/45582140/using-avplayerlooper-to-loop-through-multiple-videos) – Frankenstein Jun 19 '20 at 17:57
  • @Frankenstein The given answer is crashing without any exception/log trace. It's directly hitting AppDelegate – Tapas Pal Jun 19 '20 at 18:14

0 Answers0