Reputation: 4683
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.
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.
Upvotes: 17
Views: 9534
Reputation: 2859
You need to import AVFoundation to access AVPlayer. AVKit is (mostly) used for Mac development.
import AVFoundation
Upvotes: 32