Tariq
Tariq

Reputation: 9979

How to place check whether Video file is greater than 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.

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

Any views ?

Upvotes: 2

Views: 1008

Answers (3)

Mark Lilback
Mark Lilback

Reputation: 1164

NSURL solutions won't work because the url to a video from the user's iPod or Photo library will not be a file url, but a special scheme that the MediaPlayer or ALAssetLibrary handles. (I'm not positive on the ALAssetLibrary doing this, but I know the MediaPlayer does it and would imagine the photo library does it too so you can't muck with stuff behind its back).

The best solution I can think of is to create an AVURLAsset with the URL, and then iterate through the tracks and multiply the estimatedDataRate by the track duration in seconds. That should give you a rough size estimate for each track.

Upvotes: 0

Gypsa
Gypsa

Reputation: 11314

urlvideo contains the url of selected video file

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

Upvotes: 3

Related Questions