在我的应用程序中,我需要选择任何视频文件并显示应用程序中视频文件的 url。
-(void)viewDidLoad{
[super viewDidLoad];
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
self.imgPicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage, nil];
self.imgPicker.allowsEditing = NO;
[self presentModalViewController:self.imgPicker animated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo{
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
value = 1;
IMAGE_COUNTER = IMAGE_COUNTER + 1;
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ( [mediaType isEqualToString:@"public.movie" ])
{
NSLog(@"Picked a movie at URL %@", [info objectForKey:UIImagePickerControllerMediaURL]);
NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"> %@", [url absoluteString]);
}
else
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData* imageData = UIImageJPEGRepresentation(image, 1.0);
NSString* incrementedImgStr = [NSString stringWithFormat: @"UserCustomPotraitPic%d.jpg", IMAGE_COUNTER];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* fullPathToFile2 = [documentsDirectory stringByAppendingPathComponent:incrementedImgStr];
[imageData writeToFile:fullPathToFile2 atomically:NO];
}
}
我已经使用上面的代码显示图像和视频,一切都很好,但是当我选择任何视频文件时,它没有来到 UIImagePickerController 委托方法,视频文件直接播放,我不想播放任何视频文件,当我选择任何视频文件时,它应该出现在其委托属性中