如何解决如何在 macOS 上使用 SwiftUI 隐藏视频播放器上的按钮?
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?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。