iPhone ImagePickerController从照片库中选择视频

3

我现在正在尝试实现一个应用程序,类似于从设备照片库中选择图像和视频并将其上传到服务器...

在这里,我可以使用 uiimagepickercontroller 在表视图中显示图像和视频,但只能选择图像而不能选择视频.

如何使用 uiimagepickercontroller 从照片库中选择视频...

UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
ipc.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:ipc.sourceType];     
ipc.delegate = self;
ipc.editing = NO;
[self presentModalViewController:ipc animated:YES]; 

`


嗨,我也正在创建一个视频应用程序,最初我想从照片库中浏览视频,我已经阅读了文档并使用了文档中提供的代码,但它不起作用。它不允许我浏览视频。你能帮忙或提供一些代码吗?谢谢。 - Rocky
2个回答

8

查看文档,选择所需的类型。

myImagePickerController.mediaTypes =
    [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];

1
谢谢Max,但我的问题在didFinishPickingImage方法中,返回类型是图像,如何将其更改为视频。 - The Debugger
你使用过 UIImagePickerControllerMediaURL 吗? - Max
不,我没有使用过。你能告诉我关于它的信息吗?或者有任何相关的源代码吗? - The Debugger
请查看http://developer.apple.com/library/ios/documentation/uikit/reference/UIImagePickerControllerDelegate_Protocol/UIImagePickerControllerDelegate/UIImagePickerControllerDelegate.html#//apple_ref/occ/intfm/UIImagePickerControllerDelegate/imagePickerController:didFinishPickingMediaWithInfo:文档,它通过imagePickerController:didFinishPickingMediaWithInfo:返回字典,其中UIImagePickerControllerMediaURL是键。 - Max
嘿Max,在字典中,返回类型为空,当我选取图像时出现了什么问题? - The Debugger

0

已在 iPhone 和 iPad 上验证和测试,用于选择视频。

@property (strong,nonatomic) UIPopoverController *popOver;

属性已设置为 iPad 访问。

UIImagePickerController *videoPicker=[[UIImagePickerController alloc] init];
videoPicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
videoPicker.mediaTypes=[[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil];
videoPicker.delegate=self;

if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    UIPopoverController *popController=[[UIPopoverController alloc] initWithContentViewController:videoPicker];
    [popController presentPopoverFromRect:CGRectMake(0, 600, 160, 300) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    self.popOver=popController;
}
else
{
    [self presentViewController:videoPicker animated:YES completion:nil];
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接