Using an Unresolved AVPlayer Identifier

I found the following code on the Internet and copied and pasted it to check it, however it does not work.

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 imported the appropriate structures as shown, so it should work, but as you can see, it fails.

enter image description here

With little programming experience in iOS, I am at a loss. I would appreciate it if someone would give me a solution to this, or at least point me in the right direction.

I will be happy to provide additional information upon request.

+5
source share
1 answer

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

 import AVFoundation 
+16
source

Source: https://habr.com/ru/post/1245669/


All Articles