簡體   English   中英

無法為相機膠卷中的視頻檢索 URL Swift 5

[英]Unable to retrieve URL for video in camera roll Swift 5

下面是我的代碼:

@IBAction func selectVideoButton(_ sender: UIButton) {
    let videoPicker = UIImagePickerController()
    videoPicker.sourceType = UIImagePickerController.SourceType.photoLibrary
    videoPicker.mediaTypes = [kUTTypeImage as String, kUTTypeMovie as String]
    videoPicker.delegate = self
    present(videoPicker, animated: true, completion: nil)
}


func retrieveURL(_picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
    if let videoURL = info[.mediaURL] {
        print("Here is the URL: \(videoURL)")
        return
    }
}

我沒有收到任何錯誤,選擇視頻后應用程序不會崩潰,它似乎沒有做任何事情。 抱歉,如果某處有此問題的答案,找不到與 swift 5 或有效的答案相關的問題。

我嘗試將“任何”更改為字符串,然后相應地修改 videoURL,但這也不起作用。

您需要正確的委托方法

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

    if let videoURL = info[.mediaURL] {
        print("Here is the URL: \(videoURL)") 
    }
    picker.dismiss(animated:true,completion:nil) // add this 
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
   let videoURL = info[UIImagePickerControllerMediaURL] as? URL
   print(videoURL)
   imagePickerController.dismissViewControllerAnimated(true, completion: nil)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM