如何在 macOS 上使用 SwiftUI 隐藏视频播放器上的按钮?

Ufu*_*ker 7 avplayer video-player avkit swiftui

VideoPlayer(player: AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "*****", ofType: "mp4")!)))
Run Code Online (Sandbox Code Playgroud)

如何隐藏视频播放器上的按钮。我希望视频能够不断重复。您可以通过导入 AVKit 库来访问 VideoPlayer 对象。

import AVKit
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

jn_*_*pdx 13

要在 macOS 上隐藏视频控件(换行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) {
        
    }
}
Run Code Online (Sandbox Code Playgroud)

循环AVPlayer如何在 Swift 中循环 AVPlayer?