AVkit Bundle.main.path找不到forResource

时间:2018-06-13 21:16:33

标签: swift

我想在forResoure中显示我的视频的不同名称,所以我更改了Bundle.main.path(forResource:“已更改”),但它不起作用,它找不到合适的视频。我做错了什么? 提前谢谢。

自:

if let path=Bundle.main.path(forResource: "video1", ofType: "mp4")

TO:

if let path=Bundle.main.path(forResource: "\(datForVideo.name)", ofType: "mp4")

对complet代码可能有点帮助:

@IBAction func videoInfoButton(_ sender: Any) {
    if let path=Bundle.main.path(forResource: "video1", ofType: "mp4"){
        let video=AVPlayer(url: URL(fileURLWithPath: path))
        let videoPlay=AVPlayerViewController()
        videoPlay.player=video

        present(videoPlay, animated: true, completion: {

            video.play()
        })
    }
}

更改为:

@IBAction func videoInfoButton(_ sender: Any) {
    if let path=Bundle.main.path(forResource: "\(datForVideo.name)", ofType: "mp4"){
        let video=AVPlayer(url: URL(fileURLWithPath: path))
        let videoPlay=AVPlayerViewController()
        videoPlay.player=video

        present(videoPlay, animated: true, completion: {

            video.play()
        })
    }
}

0 个答案:

没有答案