Xcode swift - 未解决的标识符错误

时间:2016-06-08 17:44:56

标签: ios swift

请帮我编辑我的代码。我似乎无法解决这个错误。

$id_array

1 个答案:

答案 0 :(得分:2)

您必须移动avPlayer内的avPlayerViewControlerif两行,因为常量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
    }
}