3

我正在从我的应用程序中的 iphone 库中导入视频……但我无法证明我在堆栈上研究了很多代码,但没有一个在工作……对我来说……基本上我正在 fb 和 twitter 上分享…… ...

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

}

提前致谢

4

1 回答 1

4

在真正的 iPhone 设备上试用。这是我在项目中使用的从 iPhone 库中挑选视频的代码。只需将视频方法从选择器添加到您想要的按钮。

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


     }

不要忘记添加移动核心服务框架并导入

 #import <MobileCoreServices/UTCoreTypes.h>

字符串“moviepath”为您提供该 iPhone 中视频的路径,然后对该视频执行任何所需的操作,在字符串电影路径中完成压缩后,您将获得视频路径enter code here

 MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: url];   //  give here the "videourl"  
 [[player view] setFrame: [self.view bounds]];  
 [self.view addSubview: [player view]];
 [player play];
于 2012-05-16T10:26:19.343 回答