how to import Video from iphone library and play in application

穿精又带淫゛_ 提交于 2019-12-20 15:22:23

问题


i am using following code to show 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 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.


回答1:


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


来源:https://stackoverflow.com/questions/6266681/how-to-import-video-from-iphone-library-and-play-in-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!