[英]Xcode swift - unresolved identifier error
Please help me to edit my code. 请帮助我编辑代码。 I cant seem to fix this error.
我似乎无法解决此错误。
import UIKit
import AVKit
import AVFoundation
import MediaPlayer
class ViewController: UIViewController {
let avPlayerViewControler = AVPlayerViewController()
var avPlayer:AVPlayer?
var videoNumber:Int!
var url:String!
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
}
@IBAction func Cool(sender: UIButton) {
videoNumber=1
}
}
You have to move the two lines regarding the avPlayer
and avPlayerViewControler
inside the if
since the constant movieUrl
is only available inside that scope - it only exists inside the scope it was defined in, it does not exist outside of the if
-block! 你有关于两行移动
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.