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()