使用UIImagePickerController
選擇視頻後,我可以從其 [defaultRepresentation size]
中獲取視頻的文件大小。
但是,如果啓用了選取器的修剪選項,則[defaultRepresentation size]
將返回與原始未修剪視頻相同的文件大小。從UIImagePickerController獲取修剪後的視頻文件大小
沒有人有檢索修整後的視頻文件的大小的方法?
非常感謝...
是的,我應該包括一些代碼。我不好。
我試圖做到的,是讓用戶選擇和修整現有的視頻,然後上傳修剪的版本。我想要修剪版本的文件大小,以便在上傳過程中填充進度欄。我也想修剪版本的持續時間。
的調用方法:
-(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]];
的視頻確實會返回經過適當修剪的視頻。
非常感謝!
代碼片段ü試圖實現這一目標,需要返回。 – 2012-04-12 05:52:48
@ hpiOSCoder是的,我猜代碼會幫助... – 2012-04-13 16:22:15