AVKit Player View - OS X, xcode storyboard swift video player

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 Cocoa

import AVKit

import AVFoundation

import MediaPlayer


class 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)

}

}

The correct code ought to look like this:


private func loadVideo() {
     let movieURL = Bundle.main.url(forResource: "TestMovie", ofType: "mp4")!
     let player = AVPlayer(url: movieURL)
     playerView.player = player
     playerView.play()
}

If that doesn't work, be sure to say what outcome you get (error messages, which line it crashes at, what you see in the player, etc).

AVKit Player View - OS X, xcode storyboard swift video player
 
 
Q