I'm trying to figure out how to load videos with PHPicker. I know how to do it with Images but I can't seem to figure out how to do it with videos. This code works only with some videos and not with others.
Here's my code
@Binding var video: URL?
typealias UIViewControllerType = PHPickerViewController
class Coordinator: NSObject, PHPickerViewControllerDelegate {
var parent: MediaPicker
init(_ parent: MediaPicker) {
self.parent = parent
}
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
if results.isEmpty {
picker.dismiss(animated: true)
return
}
let provider = results.first!.itemProvider
if provider.hasItemConformingToTypeIdentifier(UTType.movie.identifier) {
provider.loadItem(forTypeIdentifier: UTType.movie.identifier) { url, err in
if err != nil {return}
if let url = url {
DispatchQueue.main.sync {
self.parent.video = url as! URL?
picker.dismiss(animated: true)
}
}
}
}
}
}