Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting video url from image picker in iOS

I'm facing a problem selecting the video url from the photo gallery. When the image picker is presented, it can not choose but I try to choose it. It automatically compressing and image picker is not dissmissed.

This is my code.

self.imagePickerController.sourceType = .savedPhotosAlbum
self.imagePickerController.delegate = self
self.imagePickerController.mediaTypes = [kUTTypeMovie as! String]

self.present(self.imagePickerController, animated: true, completion: nil)


func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    var videoURL: NSURL? = nil
    videoURL = info["UIImagePickerControllerReferenceURL"] as? NSURL
    print(videoURL)

    imagePickerController.dismiss(animated: true, completion: nil)
}
like image 226
mohit.dnb Avatar asked Dec 12 '25 09:12

mohit.dnb


1 Answers

In Swift 4.2, you must use a new enum provided by Apple to capture the video URL:

// Using the full key
if let url = info[UIImagePickerController.InfoKey.mediaURL] as? URL {
    // Do something with the URL
}

// Using just the information key value
if let url = info[.mediaURL] as? URL {
    // Do something with the URL
}

You can read about mediaURL here.

Specifies the filesystem URL for the movie.

like image 117
CodeBender Avatar answered Dec 15 '25 16:12

CodeBender