This is the code for a background mp4 player in swift:
func playVideoBackground(){
guard let path = Bundle.main.path(forResource: "spaceVideo", ofType: "mp4") else {
return
}
let player = AVPlayer(url: URL(fileURLWithPath: path))
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.view.bounds
playerLayer.videoGravity = .resizeAspectFill
self.videoLayer.layer.addSublayer(playerLayer)
player.play()
}
My problem with this: The video stops when finished. How can I make it loop? I found some solutions but they dont fit to my case. Can anyone modify the code to make it loop?
Thank you!