SwiftUI MacOS 应用程序 AVPlayer 无法处理视频 URL
SwifUI MacOS App AVPlayer not working with Video URL
我在 info.plist 文件中为 ios 端的 http 请求授予了权限。我已为 macOS 应用程序允许相同但无法观看视频。
错误:
代码=-1003“找不到具有指定主机名的服务器。”
AVPlayer
import AVKit
struct AVPlayerControllerRepresented : NSViewRepresentable {
var player = AVPlayer()
@Binding var playerStatus: PlayerStatus
func makeNSView(context: Context) -> AVPlayerView {
let view = AVPlayerView()
view.controlsStyle = .none
view.player = player
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: self.player.currentItem, queue: .main) { _ in
self.player.seek(to: CMTime.zero)
self.player.play()
}
return view
}
func updateNSView(_ nsView: AVPlayerView, context: Context) {
switch playerStatus {
case .start:
return player.play()
case .end:
return player.pause()
}
}
}
enum PlayerStatus {
case start
case end
}
AVPlayer 使用
AVPlayerControllerRepresented(player: AVPlayer(url: URL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!), playerStatus: $playerStatus)
我这样解决了我的问题。
我在 App Sandbox 选项卡下允许传入和传出连接。
我在 info.plist 文件中为 ios 端的 http 请求授予了权限。我已为 macOS 应用程序允许相同但无法观看视频。
错误: 代码=-1003“找不到具有指定主机名的服务器。”
AVPlayer
import AVKit
struct AVPlayerControllerRepresented : NSViewRepresentable {
var player = AVPlayer()
@Binding var playerStatus: PlayerStatus
func makeNSView(context: Context) -> AVPlayerView {
let view = AVPlayerView()
view.controlsStyle = .none
view.player = player
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: self.player.currentItem, queue: .main) { _ in
self.player.seek(to: CMTime.zero)
self.player.play()
}
return view
}
func updateNSView(_ nsView: AVPlayerView, context: Context) {
switch playerStatus {
case .start:
return player.play()
case .end:
return player.pause()
}
}
}
enum PlayerStatus {
case start
case end
}
AVPlayer 使用
AVPlayerControllerRepresented(player: AVPlayer(url: URL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!), playerStatus: $playerStatus)
我这样解决了我的问题。
我在 App Sandbox 选项卡下允许传入和传出连接。