从本地路径快速播放视频

时间:2017-05-03 07:40:03

标签: swift

我正在尝试播放使用下载管理器下载到设备的视频

这是视频路径:

  

“的/ 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()
    }

1 个答案:

答案 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)
...