gpt4 book ai didi

ios - 使用 UIImagePickerController 获取视频

转载 作者:行者123 更新时间:2023-11-28 06:50:39 25 4
gpt4 key购买 nike

我正在尝试使用 UIImagePickerController 从 iOS 应用程序中获取选定的视频,到目前为止,当单击该按钮时,它会完美打开 PhotoLibrary,我选择了一个视频,它显示 compressing video ,所以它的行为就像选择它一样,但之后什么都没有发生。我似乎真的想不通为什么。

var picker = UIImagePickerController()
var imag = UIImagePickerController()

...

@IBAction func selectMediaAction(sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary){
picker.delegate = self
picker.allowsEditing = false
picker.mediaTypes = [kUTTypeMovie as String]
self.presentViewController(picker, animated: true, completion: nil)
}
}

func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!) {
let media = editingInfo[UIImagePickerControllerOriginalImage]
let imageURL = media?.filePathURL as NSURL?
mediaPath = imageURL
mediaName.text = imageURL!.lastPathComponent
self.dismissViewControllerAnimated(true, completion: nil)
toggleSubmit()
}

@IBAction func createMediaAction(sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
imag.delegate = self
imag.allowsEditing = false
imag.sourceType = UIImagePickerControllerSourceType.Camera
imag.mediaTypes = [kUTTypeMovie as String]
self.presentViewController(imag, animated: true, completion: nil)
} else{
let alert = UIAlertController(title: nil, message: "There is no camera available on this device", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}

我错过了什么吗?在我看来它应该可以工作

最佳答案

您拥有的代码只会检查图像类型。如果你想获取选中的视频信息,你需要寻找关键UIImagePickerControllerMediaType,你需要使用委托(delegate)方法didFinishPickingMediaWithInfo而不是didFinishPickingImage

  NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

关于ios - 使用 UIImagePickerController 获取视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35002485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com