How to import video from iphone library and play application

I am using the following code to display a video library

-(IBAction)showVideoLibrary { UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init]; videoPicker.delegate = self; videoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; videoPicker.mediaTypes =[[NSArray alloc] initWithObjects: (NSString *)kUTTypeMovie,nil]; if(self.popoverController!=nil) { [self.popoverController release]; } self.popoverController = [[UIPopoverController alloc] initWithContentViewController:videoPicker]; popoverController.delegate = self; popoverController.popoverContentSize=CGSizeMake(320,1000); [popoverController presentPopoverFromRect:CGRectMake(0,0,10,10) inView:self.view permittedArrowDirections:nil animated:YES]; } 

and to get the selected video url I use the following function

 - (void)imagePickerController: (UIImagePickerController *)picker2 didFinishPickingMediaWithInfo: (NSDictionary *)info { NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType]; if([mediaType isEqualToString:@"public.movie"]) { NSLog(@"came to video select..."); NSURL *videoUrl=(NSURL*)[info objectForKey:@"UIImagePickerControllerMediaURL"]; NSLog(@"Got Movie Url==%@",videoUrl); } 

this is the code that I use, I see a list of videos present in the library, but when I click the "USE" button, it shows "Compress video". And I cannot cancel it, and I do not receive any type of URL in

 - (void)imagePickerController: (UIImagePickerController *)picker2 didFinishPickingMediaWithInfo: (NSDictionary *)info 

. Any ideas to solve this problem .. and get the application url.

Thanks.

+7
source share
1 answer

Try it on Real iPhone Device

here is the code to select the video from the iPhone library that I used in my project

Just add the video method from the selector to the desired button

  -(void)video { UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeMovie, nil]; [self presentModalViewController:imagePicker animated:YES]; } -(void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info { NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType]; if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) { NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path]; NSURL *videoUrl=(NSURL*)[info objectForKey:UIImagePickerControllerMediaURL]; // NSLog(@"%@",moviePath); if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) { UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil); } } [self dismissModalViewControllerAnimated:YES]; [picker release]; } 

Do not forget to add the infrastructure of basic services for mobile devices

and import

  #import <MobileCoreServices/UTCoreTypes.h> 

the "movie path" line gives you the path to the video on this iPhone, and then does any desired thing with this video. You will get the video path after the compression is done in the path along the movie chain, and β€œvideourl” is the URL for this video. To play this video

  MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: url]; // give here the "videourl" [[player view] setFrame: [self.view bounds]]; [self.view addSubview: [player view]]; [player play]; 
+10
source

All Articles