如何从iphone库导入视频并在应用程序中播放 [英] how to import Video from iphone library and play in application

查看:88
本文介绍了如何从iphone库导入视频并在应用程序中播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码来显示视频库

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


}

这是我正在使用的代码,我可以在库中看到视频列表,但是当我按下USE按钮时,它显示压缩视频..我无法取消它,而且我没有得到任何类型的网址

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

功能..任何解决此问题的想法..并获取应用程序的URL。

function.. Any ideas to solve this problem.. and get url in to the app.

谢谢。

推荐答案

在真正的iPhone设备上试试

Try it on Real iPhone Device

这里是从我在我的项目中使用的iPhone库中挑选视频的代码

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

并导入

 #import <MobileCoreServices/UTCoreTypes.h>

字符串moviepath为您提供iPhone中视频的路径,然后执行任何所需的操作那个视频。在字符串电影路径中完成压缩后,您将获得视频路径,并且videourl是该视频的网址播放该视频

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

这篇关于如何从iphone库导入视频并在应用程序中播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆