I am a newbie and having allot of of trouble getting the
AVKit Player View from the xcode (OS X) storyboard to simply play a mp4 video.i have placed my video
TestMovie.mp4 into the Root View ->Build Phases->Copy Bundle Resources. and also loaded in AVKit, AVFoundation, MediaPlayer in the linked frameworks and librarys tab.My AVKit Player View has been placed onto my second
NSViewController view - which is loaded from the initial view via a button.this is my current
SecondViewController swift file attached to my second view controller. where playerView has been pulled in from the stoyboard AVKit Player View. i have been trying out many different things hence the many /here is my code so far:
import Cocoaimport AVKitimport AVFoundationimport MediaPlayerclass SecondViewController: NSViewController {@IBOutlet weak var playerView: AVPlayerView!override func viewDidLoad() {super.viewDidLoad()loadVideo()}private func loadVideo() {let path = Bundle.main.path(forResource: "TestMovie", ofType:"mp4")// let path = Bundle.main.path(forResource: "TestMovie", ofType: "mp4")
//let player = AVPlayer(url: path!)
//let player = AVPlayer(url: NSURL(fileURLWithPath: path!) as URL)
//let filePathURL = NSURL.fileURL(withPath: path!)
//let player = AVPlayer(url: filePathURL)
let playerView = AVPlayer(url: URL(fileURLWithPath: path!))
//playerView.player = player
playerView.play()
}
@IBAction func joshdismiss(_ sender: Any) {
self.dismiss(self)
}
}