我試着在代碼下面選擇視頻時獲取視頻的大小,但我的應用程序已經崩潰。我想要從ALAsset
獲取每個視頻的大小,然後將它們添加到Array。怎麼可以做到這一點?請給我一些建議。謝謝。如何從ALASSET獲取視頻的大小ios
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = (UICollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
UIImageView *OverlayImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 75, 75)];
OverlayImageView.image = [UIImage imageNamed:@"Overlay-old.png"];
[cell addSubview:OverlayImageView];
alasset = [allVideos objectAtIndex:indexPath.row];
NSDate* date = [alasset valueForProperty:ALAssetPropertyDate];
NSLog(@"Date Time Modify %@",date);
//get size of video
ALAssetRepresentation *rep = [alasset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSError *error = nil;
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:&error];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
NSLog(@"Size of video %@",data);
}
謝謝,我已經做了。 – user3168540