2
VideoPlayer(player: AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "*****", ofType: "mp4")!)))

How can I hide the buttons on the VideoPlayer. I want the video to be repeated constantly. You can access the VideoPlayer object by importing the AVKit library.

import AVKit

enter image description here

jnpdx
  • 35,475
  • 5
  • 43
  • 61
Ufuk Köşker
  • 898
  • 7
  • 14

1 Answers1

3

To hide video controls on macOS (wrapping AVPlayerView):

struct ContentView: View {
    let player = AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "IMG_0226", ofType: "mp4")!))
    var body: some View {
        AVPlayerControllerRepresented(player: player)
            .onAppear {
                player.play()
            }
            .frame(width: 400, height: 400)
    }
}

struct AVPlayerControllerRepresented : NSViewRepresentable {
    var player : AVPlayer
    
    func makeNSView(context: Context) -> AVPlayerView {
        let view = AVPlayerView()
        view.controlsStyle = .none
        view.player = player
        return view
    }
    
    func updateNSView(_ nsView: AVPlayerView, context: Context) {
        
    }
}

To loop AVPlayer: How do you loop AVPlayer in Swift?

jnpdx
  • 35,475
  • 5
  • 43
  • 61