我正在使用下面的代码,但它没有显示准确的大小,假设我的文件大小为50Mb,但它显示大约90MB。
NSError *error;
NSURL * mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSDictionary * properties = [[NSFileManager defaultManager] attributesOfItemAtPath:mediaURL.path error:&error];
NSNumber * size = [properties objectForKey: NSFileSize];
我也试过下面的代码
NSDictionary *attribs = [[NSFileManager defaultManager] attributesOfItemAtPath:moviePath error:&error];
if (attribs) {
NSString *string = [NSByteCountFormatter stringFromByteCount:[attribs fileSize] countStyle:NSByteCountFormatterCountStyleFile];
NSLog(@"%@", string);
}
它也是一样的结果。我想要精确的文件大小。任何人都可以帮助我。 谢谢
答案 0 :(得分:1)
NSError *attributesError;
NSURL *videoUrl=[info objectForKey:UIImagePickerControllerMediaURL];
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[videoUrl path] error:&attributesError];
NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
long long fileSize = [fileSizeNumber longLongValue];
NSLog(@"SIZE OF VIDEO: %0.2f Mb", (float)fileSize/1024/1024);
此代码完全正常工作