Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of unresolved identifier 'AVPlayer'

Tags:

xcode

ios

swift

I found the following code on the internet and copy and pasted it to test it, however it doesn't seem to be working.

import Foundation
import UIKit
import AVKit


class Video1: UIViewController {

    var playerViewController = AVPlayerViewController()
    var playView = AVPlayer() //Unresolved identifier 'AVPlayer'

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewDidAppear(animated: Bool) {
        var fileURL = NSURL(fileURLWithPath: "/Users/User/Desktop/video.mp4")
        playerView = AVPlayer(URL: fileURL) //Unresolved identifier 'playerView'
//Unresolved identifier 'AVPlayer'

        playerViewController.player = playerView //Unresolved identifier 'playerView'

        self.presentViewController(playerViewController, animated: true){
            self.playerViewController.player?.play()
        }


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

I've imported the respective frameworks as shown, so it should work, but as seen, it fails.

enter image description here

Having little experience programming at iOS, I find myself at a loss. I would appreciate it if someone gave me a solution to this or at least point me in the right direction.

I will be happy to provide additional information if requested.

like image 478
Ren Avatar asked Mar 23 '16 22:03

Ren


1 Answers

You need to import AVFoundation to access AVPlayer. AVKit is (mostly) used for Mac development.

import AVFoundation
like image 147
Chance Hudson Avatar answered Nov 15 '22 05:11

Chance Hudson