问题描述
VideoPlayer(player: AVPlayer(url: URL(fileURLWithPath: Bundle.main.path(forResource: "*****",ofType: "mp4")!)))
如何隐藏 VideoPlayer 上的按钮。我希望视频不断重复。 您可以通过导入 AVKit 库来访问 VideoPlayer 对象。
import AVKit
解决方法
在 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
:
How do you loop AVPlayer in Swift?