【发布时间】:2012-04-12 05:47:58
【问题描述】:
使用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]]; 指向的视频确实会返回正确修剪的视频。
非常感谢!
【问题讨论】:
-
需要您尝试实现此目的的代码的 sn-p。
-
@hpiOSCoder 是的,我想代码会有所帮助...
标签: xcode set uiimagepickercontroller trim alasset