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

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

如何隐藏VideoPlayer上的按钮。 我想让视频不断重复播放。 通过导入AVKit库,您可以访问VideoPlayer对象。
import AVKit

enter image description here


这个回答解决了你的问题吗?https://dev59.com/K1EG5IYBdhLWcg3wcN3q#65928091 - jnpdx
我尝试了AVKit和AVFoundation的导入,但无法访问AVPlayerViewController。 - Ufuk Köşker
这个构建是为 macOS 还是 iOS? - jnpdx
我正在开发适用于 macOS 的应用程序。 - Ufuk Köşker
1个回答

11
隐藏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) {
        
    }
}

为了循环播放AVPlayer如何在Swift中循环使用AVPlayer?

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接