Objective c - ios:如何从Camera Roll中选择视频? [英] Objective c - ios : How to pick video from Camera Roll?

查看:145
本文介绍了Objective c - ios:如何从Camera Roll中选择视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试试这个:

 UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
videoPicker.delegate = self;
videoPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
videoPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
videoPicker.mediaTypes = @[(NSString*)kUTTypeMovie, (NSString*)kUTTypeAVIMovie, (NSString*)kUTTypeVideo, (NSString*)kUTTypeMPEG4];
videoPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
[self presentViewController:videoPicker animated:YES completion:nil];

但它只显示照片中的视频,而不是所有视频中的视频。
我想从相机胶卷中选择所有视频。
请通过提供一些线索或代码来帮助我。
提前致谢!

but it only show videos from photos part not all video in camera roll. I want to pick all video from Camera roll. Please help me by giving some clue or code. Thanks in advance!

推荐答案

以下是上述答案的汇编和清理以及更多细节。

Here is a compilation and cleanup of the answer above plus a few more details.

(0)确保你有这两个包含。

(0) Ensure you have these two includes.

#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h> // needed for video types

(1)在.h文件中添加两个代理:UINavigationControllerDelegate和UIImagePickerControllerDelegate 。对我们来说,它看起来像这样:

(1) Add two delegates to your .h file: UINavigationControllerDelegate and UIImagePickerControllerDelegate. For us, it looked like this:

@interface ATHViewController () <UITabBarDelegate, UINavigationControllerDelegate,UIImagePickerControllerDelegate>

(2)向用户提供其库中视频的选择。将此代码添加到某处的.m文件中。

(2) Present the user with choice of videos from their library. Add this code to your .m file somewhere.

    // Present videos from which to choose
    UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
    videoPicker.delegate = self; // ensure you set the delegate so when a video is chosen the right method can be called

    videoPicker.modalPresentationStyle = UIModalPresentationCurrentContext;
    // This code ensures only videos are shown to the end user
    videoPicker.mediaTypes = @[(NSString*)kUTTypeMovie, (NSString*)kUTTypeAVIMovie, (NSString*)kUTTypeVideo, (NSString*)kUTTypeMPEG4];

    videoPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
    [self presentViewController:videoPicker animated:YES completion:nil];

(3)处理来自拣货员的回复。将此代码添加到您的委托类。

(3) Handle the responses from the picker. Add this code to your delegate class.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    // This is the NSURL of the video object
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];

    NSLog(@"VideoURL = %@", videoURL);
    [picker dismissViewControllerAnimated:YES completion:NULL];
}

(4)当用户取消选择任何内容时处理。

(4) Handle when the user cancels choosing anything.

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:NULL];
}

这篇关于Objective c - ios:如何从Camera Roll中选择视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆