-1

i would like to play video files that are for example on my desktop, but i only get them playing, if i'm adding them to my project.

This works:

guard let path = Bundle.main.path(forResource: "video", ofType:"mov") else {
    return
}

avPlayerView.player = AVPlayer(url: URL(fileURLWithPath: path))
avPlayerView.player?.play()

This not:

let path = "/Users/%Username%/Desktop/mov"
avPlayerView.player = AVPlayer(url: URL(fileURLWithPath: path))
avPlayerView.player?.play()

I had a project we're a got I running, sadly i lost it.

Does anyone know what I am missing?

Thanks

  • You know that you're sandboxed, yes? You can't just grab any file you want from the user. – matt Aug 01 '22 at 23:34
  • @matt it depends. If it is running on the Simulator, then it can access the Mac file system. If it is running on a device, then it is sandboxed as you mentioned. – Jeshua Lacock Aug 01 '22 at 23:56
  • @JeshuaLacock That's false, irrelevant, or both. This is a Mac app; there is no simulator, even if what you're saying about the simulator were true, which it isn't. – matt Aug 04 '22 at 01:28

1 Answers1

-1

You have the Mac OS tag on your question, so I gather you are trying to do this on your Mac?

Is the app set up to run in the sandbox? If so, it won't have access to anything other than it's app directories (documents, caches, and a few others) and it's bundle.

The other thing you can do is display a file open dialog and then navigate to the file. The act of selecting the file implicitly grants a sandboxed app permission to open it, if I remember correctly (It's been several years since I've done sandboxed file system code for Mac OS, so my memory is a bit vague.)

Duncan C
  • 128,072
  • 22
  • 173
  • 272