使用选择视频后,UIImagePickerController
我可以从其获取视频的文件大小
[defaultRepresentation size]
。
但是,如果我启用选择器的修剪选项,[defaultRepresentation size]
则返回与原始未修剪视频相同的文件大小。
有没有人有检索修剪视频文件大小的方法?
非常感激...
是的,我应该包含一些代码。我坏。
我想要实现的是让用户选择并修剪现有视频,然后上传修剪后的版本。我想要修剪版本的文件大小,以便在上传期间填充进度条。我也想要修剪版本的持续时间。
调用方法是:
-(IBAction)selectVideoPressed:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
[videoPicker setDelegate: self];
[videoPicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[videoPicker setMediaTypes:[NSArray arrayWithObjects:(NSString *)kUTTypeMovie, nil]];
[videoPicker setVideoQuality:vvi.videoQuality];
[videoPicker setAllowsEditing:YES];
[videoPicker setModalTransitionStyle:gTransitionStyle];
[self presentViewController:videoPicker animated:YES completion:Nil];
}
}
在用户修剪并按下选择后触发的委托方法是:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[vvi setRawSourceVideoFileURL:[info objectForKey:UIImagePickerControllerMediaURL]];
[vvi setSourceVideoURL:[info objectForKey:UIImagePickerControllerReferenceURL]];
ALAssetsLibrary *assetLibrary = [[ALAssetsLibrary alloc] init];
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *myAsset)
{
// Video metrics info.
[vvi setVideoDuration:[myAsset valueForProperty:ALAssetPropertyDuration]];
[vvi setVideoOrientation:[myAsset valueForProperty:ALAssetPropertyOrientation]];
NSDate *videoDate = [myAsset valueForProperty:ALAssetPropertyDate];
[vvi setVideoDateString:[videoDate descriptionWithLocale:[NSLocale currentLocale]]];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:gShortDateFormat];
[vvi setShortVideoDateString:[dateFormatter stringFromDate:videoDate]];
ALAssetRepresentation *myAssetRepresentation = [myAsset defaultRepresentation];
[vvi setVideoAssetSize:[NSNumber numberWithLongLong:[myAssetRepresentation size]]];
NSLog(@"Duration:%@", vvi.videoDuration);
NSLog(@"Size:%@", vvi.videoAssetSize);
};
....
vvi
只是我自己的自定义类。两个 NSLog 返回原始未修剪视频的持续时间和大小。指向的视频[vvi setRawSourceVideoFileURL:[info objectForKey:UIImagePickerControllerMediaURL]];
确实返回了正确修剪的视频。
非常感谢!