2

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

4

1 回答 1

4

您可以从 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]);
}

迅速:

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)")
}
于 2012-10-11T12:49:36.140 回答