can't get extremely simple macOS video player to work...

... following Apple's example. Going off of this tutorial:

https://developer.apple.com/documentation/avfoundation/media_playback_and_selection/creating_a_basic_video_player_macos

I have dragged into the storyboard the AVKit Player View, and here is my ViewController code:

Code Block
import Cocoa
import AVKit
import AVFoundation
class ViewController: NSViewController {
   
   
  @IBOutlet weak var playerView: AVPlayerView!
   
  override func viewDidLoad() {
    super.viewDidLoad()
     
    guard let url = URL(string: "linkWasHere") else {
        return //could not post actual link due to this forum's security issues, see link above for actual link. ???
    }
     
    let player = AVPlayer(url: url)
    playerView.player = player
  }
}


here is what the console is outputting when I run this, any idea why this no longer works?

2020-11-01 20:28:31.491145-0800 Player01[13477:15207676] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x60000025c420> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2020-11-01 20:28:31.494171-0800 Player01[13477:15207338] CDN - client insert callback function client = 0 type = 17 function = 0x7fff3a9f3246 localolny = false
2020-11-01 20:28:31.494205-0800 Player01[13477:15207338] CDN - client setup
remoteport
2020-11-01 20:28:31.494227-0800 Player01[13477:15207338] CDN - Bootstrap Port: 1799
2020-11-01 20:28:31.494332-0800 Player01[13477:15207338] CDN - Remote Port: 36867 (com.apple.CoreDisplay.Notification)
2020-11-01 20:28:31.494366-0800 Player01[13477:15207338] CDN - client setup
localport
2020-11-01 20:28:31.494385-0800 Player01[13477:15207338] CDN - Local Port: 28419
2020-11-01 20:28:31.524528-0800 Player01[13477:15207676] HALC
ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2020-11-01 20:28:31.539261-0800 Player01[13477:15207338] Metal API Validation Enabled
2020-11-01 20:28:31.692487-0800 Player01[13477:15207700] startConfigurationWithCompletionHandler: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd}
2020-11-01 20:28:31.692614-0800 Player01[13477:15207700] startConfigurationWithCompletionHandler: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd}
2020-11-01 20:28:31.712175-0800 Player01[13477:15207701] dnssdclientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:11 Err:-1 Errno:1 Operation not permitted
2020-11-01 20:28:31.712371-0800 Player01[13477:15207701] [] nw
resolvercreatednsservicelocked [C1] DNSServiceCreateDelegateConnection failed: ServiceNotRunning(-65563)
2020-11-01 20:28:31.712656-0800 Player01[13477:15207701] Connection 1: received failure notification
2020-11-01 20:28:31.716191-0800 Player01[13477:15207701] Connection 1: failed to connect 10:-72000, reason -1
2020-11-01 20:28:31.716310-0800 Player01[13477:15207701] Connection 1: encountered error(10:-72000)
2020-11-01 20:28:31.716980-0800 Player01[13477:15207700] Task <4869798A-2285-4453-8ED6-D7F3DA7E2758>.<1> HTTP load failed, 0/0 bytes (error code: -1003 [10:-72000])
2020-11-01 20:28:31.718743-0800 Player01[13477:15207718] Task <4869798A-2285-4453-8ED6-D7F3DA7E2758>.<1> finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={kCFStreamErrorCodeKey=-72000, NSUnderlyingError=0x600000cbf6f0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={kCFStreamErrorCodeKey=-72000, kCFStreamErrorDomainKey=10}}, NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <4869798A-2285-4453-8ED6-D7F3DA7E2758>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
  "LocalDataTask <4869798A-2285-4453-8ED6-D7F3DA7E2758>.<1>"
), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8, NSErrorFailingURLKey=https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8, _kCFStreamErrorDomainKey=10}
2020-11-01 20:28:31.719376-0800 Player01[13477:15207676] sendMessageWithDictionary: Failed to get remote object proxy: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.rtcreportingd" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.rtcreportingd}

Replies

ah... figuring some stuff out thank to this SO post:

https://stackoverflow.com/questions/47127618/avplayer-wont-let-me-access-url
AHA! Here is the answer... must use "let fileURL = URL(fileURLWithPath: "myPath")... the below code works for Swift 5.3 and uses a button to allow user to choose internal video. See above SO link for things you need to do to play external video.

Code Block
import Cocoa
import AVKit
import AVFoundation
class ViewController: NSViewController {
   
   
  @IBOutlet weak var playerView: AVPlayerView!
  @IBOutlet weak var chooseVideoButton: NSButton!
   
  var path: String = ""
   
   
  override func viewDidLoad() {
    super.viewDidLoad()
     
  }
   
  @IBAction func chooseVideoPressed(_ sender: NSButton)
  {
    let dialog = NSOpenPanel();
    dialog.title          = "Choose a video";
    dialog.showsResizeIndicator  = true;
    dialog.showsHiddenFiles    = false;
    dialog.allowsMultipleSelection = false;
    dialog.canChooseDirectories = false;
    if (dialog.runModal() == NSApplication.ModalResponse.OK) {
      let result = dialog.url // Pathname of the file
      if (result != nil) {
        path = result!.path
      }
       
      //let fileURL = URL(string: path)
      let fileURL = URL(fileURLWithPath: path)
      let avAsset = AVURLAsset(url: fileURL, options: nil)
      let playerItem = AVPlayerItem(asset: avAsset)
      let videoPlayer = AVPlayer(playerItem: playerItem)
      playerView.player = videoPlayer
      videoPlayer.play()
       
    } else {
      // User clicked on "Cancel"
      return
    }
  }
   
}