简体   繁体   中英

How can I get the size of the video that is taken from UIimagePicker?

I am using below code but it is not showing accurate size,Suppose my file size is 50Mb,But it is showing around 90MB.

NSError *error;
NSURL * mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSDictionary * properties = [[NSFileManager defaultManager] attributesOfItemAtPath:mediaURL.path error:&error];
NSNumber * size = [properties objectForKey: NSFileSize];

and also i tried below code

NSDictionary *attribs = [[NSFileManager defaultManager] attributesOfItemAtPath:moviePath error:&error];
if (attribs) {
    NSString *string = [NSByteCountFormatter stringFromByteCount:[attribs fileSize] countStyle:NSByteCountFormatterCountStyleFile];
    NSLog(@"%@", string);
}

It is also same result.I want exact file size.Can any body help me. Thank you

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

This code is completely work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM