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.
You need to import AVFoundation to access AVPlayer. AVKit is (mostly) used for Mac development.
import AVFoundation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With