0

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!

1 Answers1

-1

You can do this using threads and do a control

Timer.scheduledTimer(withTimeInterval: time, repeats: true) { _ in
            self.playVideoBackground()
        }