如何导入从iphone库中的视频,并在应用程序中播放

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

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

以及用于接收所选择的视频网址我使用下面的函数

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

这是我使用的代码,我可以看到视频的出现在库列表,但是当我按下“使用”按钮,它显示压缩视频..而我是无法取消它,我没有得到任何形式的网址在

- (void)imagePickerController: (UIImagePickerController *)picker2 didFinishPickingMediaWithInfo: (NSDictionary *)info

功能..任何想法来解决这个问题..并在该应用程序取得网址。

谢谢。

--------------解决方案-------------

试试它真正的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则​​与该视频进行任何需要的东西。 压缩在字符串电影路径和“videourl”完成后,您将获得的视频路径是URL该视频要播放视频

MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: url]; // give here the "videourl"
[[player view] setFrame: [self.view bounds]];
[self.view addSubview: [player view]];
[player play];

分类:Xcode中 时间:2014-08-15 人气:0
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 1.324 (s). 10 q(s)