I am playing around with the PHPickerViewController and so far I was able to get the selected images by loading them into UIImage instances but I don't know how to get the selected video.
Below is the relevant implementation of the method: func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]):
Code Block let provider = result.itemProvider guard provider.hasItemConformingToTypeIdentifier(AVFileType.mov.rawValue) else { return } provider.loadItem(forTypeIdentifier: AVFileType.mov.rawValue, options: nil) { (fileURL, error) in if let error = error { print(error) return } guard let videoURL = fileURL as? URL else { return } DispatchQueue.main.async { let fm = FileManager.default let destination = fm.temporaryDirectory.appendingPathComponent("video123.mov") try! fm.copyItem(at: videoURL, to: destination) let playerVC = AVPlayerViewController() playerVC.player = AVPlayer(url: destination) self.present(playerVC, animated: true, completion: nil) } }
I get crash trying to copy the item. It says the source file does not exists but the path looks real to me.
I tried it without copying first and just passing the URL to AVPlayer but nothing would play."The file “3C2BCCBC-4474-491B-90C2-93DF848AADF5.mov” couldn’t be opened because there is no such file."
I am testing this on a simulator.
Thanks for help!