How To Loop Video In SwiftUI

Anyone got sample code for using AVPlayerLooper in SwiftUI?

Code i see are not for SwiftUI

I only wish to have the option to turn on auto-repeat on and off.

I could use AVQueuePlayer as replacement for AVPlayer but it does not have a way to loop.

So these are what I am looking for

  1. Loop video in SwiftUI
  2. If Using AVPlayerLooper, it has a disableLooping() function (possibly to turn off looping). But how can it be turned back on? There is no enableLooping(). Or does it need a new instance?
  3. since i am new to iOS, the code there are all linked to no swift ui code so I have no clue (sorry) the equivalent of them in SwiftUI

Thoughts?

Answered by dave450 in 747110022

I've used this approach and it works well: https://schwiftyui.com/swiftui/playing-videos-on-a-loop-in-swiftui/

Accepted Answer

I've used this approach and it works well: https://schwiftyui.com/swiftui/playing-videos-on-a-loop-in-swiftui/

@dave450 I decided to keep using VideoPlayer(player: AVPlayer) and add/remove an observer where after the video ends, it will play back to the first frame.

How To Loop Video In SwiftUI
 
 
Q