我们能否在图像选择器委托中计算用户录制或从保存的图像文件夹中选择的视频大小(以字节为单位)?谢谢。
我们能否在图像选择器委托中计算用户录制或从保存的图像文件夹中选择的视频大小(以字节为单位)?谢谢。
您可以轻松地从NSData对象中读取字节数。因此,您唯一需要做的就是从视频URL创建NSData对象。
像这样:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
NSURL *imageURL = [info valueForKey:UIImagePickerControllerMediaURL];
NSData *data = [NSData dataWithContentsOfURL:imageURL];
NSLog(@"Total bytes %d", [data length]);
}
Swift:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
picker.dismissViewControllerAnimated(true, completion: nil)
let imageUrl = info[UIImagePickerControllerMediaURL]
let data = NSData(contentsOfURL: imageUrl)
print("Total bytes \(data.length)")
}