0

我正在使用ELCImagePickerController多个视频选择。但我想获得所选视频的大小。当用户点击任何视频时,他们的视频大小就会被检查。

现在,所有选定的视频信息都在输入:

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

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

我可以在didFinishPickingMediaWithInfo:方法中找到视频大小。但是当用户选择所有视频时会调用此方法。但我想限制用户选择大尺寸文件。

我想在用户单击视频时获取视频信息,如果用户单击一个视频,则获取该视频大小并显示与大尺寸相关的警报。当用户点击视频进行选择时,会调用以下内容。但我目前无法获取视频信息。

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;
}
4

1 回答 1

1

检查以下代码长度:`

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:yourVideoUrl];

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

检查以下代码大小:

一千字节有 1024 字节,一兆字节有 1024 千字节

NSData * movieData = [NSData dataWithContentsOfURL:yourVideoUrl];

NSLog(@"%.2f",(float)movieData.length/1024.0f/1024.0f);
于 2014-05-23T08:46:18.963 回答