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) { = guardian

    func imagePickerController (
        _ picker: UIImagePickerController,
        didFinishPickingMediaWithInfo data: [UIImagePickerController.InfoKey: Any]
    ) {
        if let mediaType = data[.mediaType] as? String,
              mediaType ==,
              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


    // high blue cancel
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        @ObservedObject var fileInfo = SharedFileInfo.shared
        fileInfo.menuIndex = 0

func makeCoordinator() -> Coordinator {
    return Coordinator(guardian: self)

func makeUIViewController(context: Context) -> UIImagePickerController {
    let picker = UIImagePickerController()
    picker.delegate = context.coordinator
    picker.sourceType = .photoLibrary
    picker.mediaTypes = []
    picker.allowsEditing = false

    return picker

func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {}



Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button