title: How to embed and stream a video from the web within an Xcode macOS Cocoa Application?
body: <p>I am trying to get my <strong>macOS Cocoa Application</strong> Xcode project to play some video when I feed it a specified URL. </p>
  
  <p>To simplify the question lets just use an empty Xcode project. </p>
  
  <p>I want to achieve the same level of control as I am able to get using <code>AVPlayerViewController()</code> in my <strong>iOS Single View Application</strong>. Within that app I am currently using the solution offered <a href="https://stackoverflow.com/a/31277658/4041795">here</a>.  </p>
  
  <p><strong>However, only the second example works in my macOS Cocoa Application when adapted like so</strong>:</p>
  
  <pre><code>import Cocoa
  import AVFoundation
  import AVKit
  
  class ViewController: NSViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
          let player = AVPlayer(url: videoURL!)
          let playerLayer = AVPlayerLayer(player: player)
          playerLayer.frame = self.view.bounds
          self.view.layer?.addSublayer(playerLayer)
          player.play()
  
      }
  
      override var representedObject: Any? {
          didSet {
          // Update the view, if already loaded.
          }
      }
  
  
  }
  </code></pre>
  
  <p>This option however has <strong>2 downsides</strong>:</p>
  
  <ol>
  <li><p>It creates a repetitive error message in the console:</p>
  
  <pre><code>2017-06-27 18:22:06.833441+0200 testVideoOnmacOS[24456:1216773] initWithSessionInfo: XPC connection interrupted
  2017-06-27 18:22:06.834830+0200 testVideoOnmacOS[24456:1216773] startConfigurationWithCompletionHandler: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service named com.apple.rtcreportingd}
  </code></pre></li>
  <li><p>This <code>AVPlayer</code> solution does not offer the same control as the <code>AVPlayerViewController()</code> solution.  </p></li>
  </ol>
  
  <p><strong>So I attempted to get the following AVPlayerViewController() solution to work. But it fails:</strong></p>
  
  <pre><code>import Cocoa
  import AVFoundation
  import AVKit
  
  class ViewController: NSViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          let videoURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
          let player = AVPlayer(url: videoURL!)
          let playerViewController = AVPlayerViewController()
          playerViewController.player = player
          self.present(playerViewController, animated: true) {
              playerViewController.player!.play()
          }
  
      }
  
      override var representedObject: Any? {
          didSet {
          // Update the view, if already loaded.
          }
      }
  
  
  }
  </code></pre>
  
  <p>The error I am getting is: </p>
  
  <blockquote>
    <p>Use of unresolved identifier 'AVPlayerViewController' - Did you mean
    'AVPlayerViewControlsStyle'?</p>
  </blockquote>
  
  <p>I have tried to work around this in many different ways. It will be confusing if I spell them all out. My prominent problem seems to be that the vast majority of online examples are iOS based. </p>
  
  <blockquote>
    <p>Thus, the main question: </p>
    
    <p><strong>How would I be able to successfully use AVPlayerViewController within my Xcode macOS Cocoa Application?</strong></p>
  </blockquote>