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?

Accepted Reply

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

  • Thank you. will check this out

  • @dave450 were you able to show the player controls as well? I read the comments and while they say it does loop, the problem is showing the player controls

Add a Comment

Replies

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

  • Thank you. will check this out

  • @dave450 were you able to show the player controls as well? I read the comments and while they say it does loop, the problem is showing the player controls

Add a Comment

@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.