how to import Video from iphone library and play in application
i am using following code to show video library
-(IBAction)showVideoLibrary
{
UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
videoPicker.delegate = self;
videoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
videoPicker.开发者_C百科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 for receiving the selected Video Url i am using 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 i am using, i can see list of video's present in library, but when i press "USE" button, it is showing Compressing video.. and i am unable to cancel it, and i am not getting any kind of url in the
- (void)imagePickerController: (UIImagePickerController *)picker2 didFinishPickingMediaWithInfo: (NSDictionary *)info
function.. Any ideas to solve this problem.. and get url in to the app.
Thanks.
Try it on Real iPhone Device
here is the code for picking video from iPhone library which i have used in my project
Just add video method from selector to your 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 mobile core services framework
and to import
#import <MobileCoreServices/UTCoreTypes.h>
the string "moviepath" give you the path of the video in that iPhone then perform any desired thing with that video. You will get video path after compressing is done in string movie path and "videourl" is url for that video To play that video
MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: url]; // give here the "videourl"
[[player view] setFrame: [self.view bounds]];
[self.view addSubview: [player view]];
[player play];
精彩评论