如何在我的xcode 8项目中修复“init(URL :)已重命名为init(url :)”错误?

时间:2017-07-28 18:12:40

标签: swift3 xcode8

如何修复

  

init(URL :)已重命名为init(url :)

我的Xcode 8项目出现

错误? 这是我的代码:

 override func viewDidLoad() {
            super.viewDidLoad()

    // Load the video from the app bundle.
    let videoURL: NSURL = Bundle.main.url(forResource: "IMG_4628", withExtension: "mp4")! as NSURL

    player = AVPlayer (URL: videoURL)
    player?.actionAtItemEnd = .none
    player?.isMuted = true

    let playerLayer = AVPlayerLayer(player: player)
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
    playerLayer.zPosition = -1

    playerLayer.frame = view.frame

    view.layer.addSublayer(playerLayer)

    player?.play()

    //loop video

如何解决行player = AVPlayer(URL: videoURL)中的错误? 感谢。

2 个答案:

答案 0 :(得分:1)

您应该在初始化程序中用URL替换大写的url

player = AVPlayer(url: videoURL)

答案 1 :(得分:0)

只需使用以下代码替换。

player = AVPlayer(url:videoURL!as URL)