Это решение, которое я нашел:
Чтобы сохранить выбранное видео:
func saveVideoToDirectory(videoUrl: NSURL) {
let videoData = NSData(contentsOf: videoUrl as URL)
let path = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let newPath = path.appendingPathComponent("/backgroundVideo.mp4")
do {
try videoData?.write(to: newPath)
let movieData = NSKeyedArchiver.archivedData(withRootObject: newPath)
UserDefaults.standard.set(movieData, forKey: "movie")
//print("movie url: ", newPath)
} catch {
print(error)
}
}
, чтобы получить видео:
let movieData = UserDefaults.standard.object(forKey: "movie") as? Data
let movieUrl = NSKeyedUnarchiver.unarchiveObject(with: data) as! URL
//search for current documents path
let docPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let videoUrl = URL(fileURLWithPath: docPath.appendingFormat("/backgroundVideo.mp4"))
let playerItem = AVPlayerItem(url: videoUrl as URL)