简体   繁体   中英

How to check selected video size using ELCImagePickerController

I am using ELCImagePickerController for multiple video selection. But I want to get size of selected video. When user click on any video, then their video size is check.

Right now, all selected video information is getting in:

- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
 for (NSDictionary *dict in info) {
   NSUrl *video url = [dict objectForKey:UIImagePickerControllerReferenceURL];

NSLog(@"Video information is ::",url);
       }
} 

I can find the video size in didFinishPickingMediaWithInfo: method . But this method is called when user select all video. But I want to restrict user from selection of large size file.

I want to get video information when a user click on video ,If user click on one video then that video size is get and show a alert related to large size . Following is called when user tap on a video for selecting. But I am unable to get video information at this time .

ELCImagePickerController.m

- (BOOL)shouldSelectAsset:(ELCAsset *)asset previousCount:(NSUInteger)previousCount
{
    BOOL shouldSelect = previousCount < self.maximumImagesCount;
    if (!shouldSelect) {
        NSString *title = [NSString stringWithFormat:NSLocalizedString(@"Only %d Video please!", nil), self.maximumImagesCount];
        NSString *message = [NSString stringWithFormat:NSLocalizedString(@"You can only upload %d Videos at a time.", nil), self.maximumImagesCount];
        [[[UIAlertView alloc] initWithTitle:title
                                    message:message
                                   delegate:nil
                          cancelButtonTitle:nil
                          otherButtonTitles:NSLocalizedString(@"Okay", nil), nil] show];
    }
    return shouldSelect;
}

Check the below code Length:`

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:yourVideoUrl];

CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"duration: %.2f", seconds);`

Check the below code Size:

There are 1024 bytes in a kilobyte and 1024 kilobytes in a megabyte

NSData * movieData = [NSData dataWithContentsOfURL:yourVideoUrl];

NSLog(@"%.2f",(float)movieData.length/1024.0f/1024.0f);

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