计算imagepickerdidFinishPickingMediaWithInfo中视频的大小(以字节为单位)

时间:2012-10-11 11:41:23

标签: iphone ios uiimagepickercontroller

我们可以计算用户录制的视频或用户从图像选择器委托内的已保存图像文件夹中选择的视频大小(以字节为单位)吗?谢谢

1 个答案:

答案 0 :(得分:3)

您可以从NSData对象轻松读取字节大小。 因此,您唯一需要做的就是从视频网址创建一个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]);
}

夫特:

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)")
}