我有一个UIPickerController可以在我的应用程序中选择视频,并且在使用选择器选择视频时会崩溃。当我直接使用URL提供MPMoviePlayerController时,它可以正常工作,但是当URL来自UIPickerController时,它会正确加载电影,但在创建缩略图时会崩溃。
我已经将URL转储到控制台,就在选择了文件之后,这就是我所看到的
file://localhost/private/var/mobile/Applications/FA667F85-B009-46FA-A0B9-A7345A072651/tmp//trim.Ir0gqx.MOV
第一个问题:为什么文件名前面有双栏? 第二个问题:如果我在选择器上编辑NO,为什么文件名带有修剪前缀?
这是选择器代码:
- (void) selectMovie:(id) sender {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
picker.delegate = self;
picker.allowsEditing = NO;
picker.videoQuality = UIImagePickerControllerQualityTypeHigh; // I've added this trying to make it stop compressing the video, but it won't... any clues?
UIPopoverController *aPopover =
[[UIPopoverController alloc] initWithContentViewController:picker];
aPopover.delegate = self;
CGRect myRect = [sender frame];
[aPopover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ( [ mediaType isEqualToString:@"public.movie" ]){
movieURL = [info objectForKey:UIImagePickerControllerMediaURL];
}
NSLog(@"%@", movieURL);
[self loadMovie:movieURL];
}
答案 0 :(得分:1)
我的想法是,您的应用无权在电影存储位置生成缩略图。尝试将影片文件从相册中复制到文档目录中:
NSFileManager *fm = [NSFileManager defaultManager];
[fm moveItemAtURL:fromURL toURL:toURL error:&error];
假设你有一个toURL指向docs目录中的文件名。
答案 1 :(得分:0)
我只知道第一个,因为你需要向MPMoviePlayerController提供一个url,一个url必须从一个方案开始,http://, smtp://
,那种。 file://
也是文件网址