我使用UIImagePickerController
拍摄视频后创建了相机。我点击了使用视频,我将此视频保存到了照片库。现在我想获得这部影片的大小。我用AlAssetLibrary
将视频保存到照片库。如何才能获得视频的大小?请帮帮我。提前致谢。将此视频保存到iOS中的照片库后获取视频大小
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSURL *recordedVideoURL= [info objectForKey:UIImagePickerControllerMediaURL];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:recordedVideoURL]) {
[library writeVideoAtPathToSavedPhotosAlbum:recordedVideoURL
completionBlock:^(NSURL *assetURL, NSError *error){}
];
}
}
我想下面的代码,以获得视频的大小,但不工作:
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];
它是如何失败? –
我不知道,但当我的应用程序崩溃时,通过使用上面的代码获取视频的大小。 – user3168540
也许视频非常大,你的应用正在被内存压力所杀。 –