我正在尝试播放使用下载管理器下载到设备的视频
这是视频路径:
“的/ var /移动/容器/数据/应用/ CFFBEE5C-0AFD-40BB-A66C-7879879CFAA0 /文档/ MyDownloads / Arrow.S05E01.mp4”
我正在使用此代码播放视频:
let player = AVPlayer(url: URL(fileURLWithPath: path))
let playerController = AVPlayerViewController()
playerController.player = player
present(playerController, animated: true) {
player.play()
}
答案 0 :(得分:2)
不要使用文字字符串路径。获取包含Documents
的当前FileManager
文件夹:
let documentsFolder = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let videoURL = documentsFolder.appendingPathComponent("MyDownloads/Arrow.S05E01.mp4")
let player = AVPlayer(url: videoURL)
...