0

我正在使用下面的代码,但它不显示准确的大小,假设我的文件大小是50Mb,但它显示大约90MB。如何获取从UIimagePicker获取的视频大小?

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

它也同样result.I想确切的文件size.Can任何机构帮助我。 谢谢

+0

有你提到的SO,http://stackoverflow.com/a/27245011/6742121这个答案? @Bittoo – KAR

+0

其实我在压缩视频后得到这个结果。但是在压缩视频尺寸增加之后是有原因的。 – Bittoo

回答

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); 

此代码是完全正常工作

+0

已经尝试过,但没有use.did你使用这段代码得到确切大小的视频? – Bittoo

+0

是Rajat.It对我来说非常合适。 –

+0

不,它不适用于我 – Bittoo