how to import Video from iphone library and play in application

后端 未结 1 1696
我寻月下人不归
我寻月下人不归 2021-02-06 07:54

i am using following code to show video library

 -(IBAction)showVideoLibrary
{
UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
vid         


        
1条回答
  •  情歌与酒
    2021-02-06 08:32

    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 
    

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

    0 讨论(0)
提交回复
热议问题