Hi I just wanted to document an issue I was having with the accepted answer and my solution to fix it just in case anyone is running into the same issue as me. When I used the
let newUrl = URL(fileURLWithPath: NSTemporaryDirectory() + fileName) for videos my AVPlayer was not able to play the video from this local file url. I was getting the error where the AVPlayer's play button had a line through it and then black screen. My solution to fix this bug was to use the userDomainMask to make sure the file was accessible. Here it is:
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let newURL = documentsURL.appendingPathComponent("temp.mov")
do {
try FileManager.default.copyItem(at: url, to: newURL)
} catch {
print("File manager copy failed")
}