我想在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()
})
}
}