5
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
  • 45,847
  • 6
  • 64
  • 94
Ufuk Köşker
  • 1,288
  • 8
  • 29

1 Answers1

8

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
  • 45,847
  • 6
  • 64
  • 94