AVPlayer won't play local files until a add them to the project

Hi, 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

Your app may not have permission to open arbitrary paths. In some configurations, the user has to explicitly grant permission for your app to access files on disk, for example by choosing the file from an open panel presented by your app. I'd check AVPlayerItem.status and AVPlayerItem.error on your player's current item to see what went wrong.

Hi, I've found this solution to play a movie in user document's folder: let url = URL(fileURLWithPath: path + "/" + filename)

AVPlayer won't play local files until a add them to the project
 
 
Q