ios - objective-c - ios : How to pick video from Camera Roll?

标签 ios objective-c iphone xcode uiimagepickercontroller

我试试这个:

 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];

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

最佳答案

这是对上述答案的汇编和清理以及一些更多细节。

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

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

(1) 将两个委托(delegate)添加到您的 .h 文件:UINavigationControllerDelegate 和 UIImagePickerControllerDelegate。对于我们来说,它看起来像这样:

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

(2) 向用户展示他们图书馆中的视频选择。将此代码添加到您的 .m 文件中的某处。

    // 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) 处理来自选择器的响应。将此代码添加到您的委托(delegate)类中。

- (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) 当用户取消选择时处理。

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

关于ios - objective-c - ios : How to pick video from Camera Roll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30882321/

相关文章:

iphone - UIScrollView 内部 UIView 的 DrawRect

iphone - 创建到 NSMutableArray 时动态计算 TextField

iphone - 在 UITableView 中选择 UIImage

javascript - getJSON 适用于 Android 但不适用于 IOS

ios - 核心数据+组合架构

objective-c - 在 MVVM 中放置 delegate 的正确位置是什么

ios - 如何在Pod项目ViewController中导入AppDelegate.h文件?

ios - 当我播放嵌入的YouTube视频时,如何将我的iOS应用名称作为流量来源传递?

objective-c - float uiview subview 在滚动时消失

ios - 将 NS_OPTIONS 枚举 (UIRemoteNotificationType) 位掩码转换为 NSString 分隔值