从 iOS 中的图像选择器获取视频 url

moh*_*dnb 3 uiimagepickercontroller ios swift

我在从照片库中选择视频网址时遇到问题。当图像选择器出现时,它无法选择,但我尝试选择它。它会自动压缩并且图像选择器不会被关闭。

这是我的代码。

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)
}
Run Code Online (Sandbox Code Playgroud)

Cod*_*der 7

在Swift 4.2中,您必须使用 Apple 提供的新枚举来捕获视频 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
}
Run Code Online (Sandbox Code Playgroud)

mediaURL 您可以在这里阅读有关内容。

指定电影的文件系统 URL。