-1

I was trying to make a video player in Xcode by following a youtube tutorial as I'm very new to coding but it keeps saying "Use of unresolved identifier: 'present'"

import UIKit

import AVKit

class VideoP: NSObject {

@IBAction func vidButton(_ sender: Any) {
    if let path = Bundle.main.path(forResource: "video", ofType: "mp4")
    {
        let video =  AVPlayer(url: URL(fileURLWithPath: path))
        let videoPlayer = AVPlayerViewController()
        videoPlayer.player = video
        present(videoPlayer, animated: true, completion:
            {
                video.play()
        })

    }
}
 }

sorry if this is a confusing question as I said I'm very new!

Laurcode
  • 17
  • 4
  • This code works as is if VideoP were a view controller (see arash's answer). NSObject doesn't have a present method. – Mozahler Apr 21 '18 at 11:52

1 Answers1

1

present is the method of the UIView, then you can't use it on a class.
you should write it in your UIViewController like below:

self.present(videoPlayer, animated: true, completion:
        {
            video.play()
})
Arash Etemad
  • 1,827
  • 1
  • 13
  • 29