请帮我编辑我的代码。我似乎无法解决这个错误。
$id_array
答案 0 :(得分:2)
您必须移动avPlayer
内的avPlayerViewControler
和if
两行,因为常量movieUrl
仅在该范围内可用 - 只有在其定义的范围内存在,它不存在于if
- 块之外!
override func viewDidLoad() {
super.viewDidLoad()
let urlpathString:String? = NSBundle.mainBundle().pathForResource("url", ofType: "mp4")
if let urlPath = urlpathString {
switch videoNumber {
case 1 : url="20"
case 2 : url="10"
default : break
}
let movieUrl = NSURL(fileURLWithPath: urlPath)
self.avPlayer = AVPlayer(URL: movieUrl)
self.avPlayerViewControler.player = self.avPlayer
}
}