iOS Development
ios – Selecting A Video File From PhotoLibrary With SwiftUI

I’m utilizing following code to get video’s URL that are in picture library.
It presents checklist of video recordsdata in picture library and also you select certainly one of them.
It then opens an different view with cancel, play and select buttons at backside.
You must contact select button right here once more to get URL of the video file.
I wish to get URL at first step however how.
struct VideoPickerView: UIViewControllerRepresentable {
var videoURL: URL?
@Setting(.presentationMode) non-public var presentationMode
class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
var guardian: VideoPickerView
init(guardian: VideoPickerView) {
self.guardian = guardian
}
func imagePickerController (
_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo data: [UIImagePickerController.InfoKey: Any]
) {
if let mediaType = data[.mediaType] as? String,
mediaType == UTType.film.identifier,
let videoURL = data[.mediaURL] as? URL ?? data[.mediaURL] as? URL {
// Deal with the video URL
print("url (videoURL)")
@ObservedObject var fileInfo = SharedFileInfo.shared
guardian.videoURL = videoURL
fileInfo.videoURL = videoURL
fileInfo.menuIndex = 34
}
guardian.presentationMode.wrappedValue.dismiss()
}
// high blue cancel
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
@ObservedObject var fileInfo = SharedFileInfo.shared
fileInfo.menuIndex = 0
guardian.presentationMode.wrappedValue.dismiss()
}
}
func makeCoordinator() -> Coordinator {
return Coordinator(guardian: self)
}
func makeUIViewController(context: Context) -> UIImagePickerController {
let picker = UIImagePickerController()
picker.delegate = context.coordinator
picker.sourceType = .photoLibrary
picker.mediaTypes = [UTType.movie.identifier]
picker.allowsEditing = false
return picker
}
func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {}
}
Credit: www.ismmailgsm.com