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