如何放置检查视频文件是否大于2MB?

问题描述:

假设我从iphone库中获取了一个视频文件.我想检查一下视频文件不应大于2MB.

Suppose I have taken a video file from iphone library. I want to put a check that Video file shouldn't be greater than 2MB.

我不能使用videoMaximumDuration方法.因为如果任何视频都是高清质量的,那么即使是1分钟长的视频也可能会很大.

I cant use videoMaximumDuration method. Because if any video is hd quality even 1 min duration video could be huge in size.

任何意见?

urlvideo包含所选视频文件的网址

            NSString *strurl=[urlvideo path];
            NSFileManager *fileManager = [NSFileManager defaultManager];
            NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:strurl error:nil];

        if(fileAttributes != nil)
            {
                NSString *fileSize = [fileAttributes objectForKey:NSFileSize];
                //NSLog(@"File size: %@ kb", fileSize);             
                if ([fileSize intValue] > 2000000) {                    
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"File size greater than 2MB.Please select another video file." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [alert show];
                    [alert release];
                }               
                else {
NSLog(@"video size less than 2 mb");
    }