我正在ipad上做一个应用程序,它将捕获视频,它将保存在照片库中。但我想要的是我想从照片库中选择播放那个视频并需要在那里播放。我看到很多使用MPMoviePlayerController
的例子,但我看到的是他们在那里添加视频并播放该视频.Is有没有办法为我下面提到的代码编写路径。
我的代码在这里
我在这里调用照片库
-(IBAction) goToPhotos:(id)sender {
ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
ipc.allowsEditing = YES;
UIPopoverController *videoController = [[UIPopoverController alloc]initWithContentViewController:ipc];
// pop.popoverContentSize = CGSizeMake(300, 900);
[videoController presentPopoverFromRect:[sender frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
[ipc release];
[self presentModalViewController:ipc animated:YES];
}
我在这里打电话给MPMoviePlayerController
.Code就在这里
- (void)viewDidLoad
{
NSString *url = [[NSBundle mainBundle]
pathForResource:@"Stock_Footage_Demobroadband"
ofType:@"mp4"];
MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]];
[self.view addSubview:playerViewController.view];
//---play movie---
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
[super viewDidLoad];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification
{
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[self.view removeFromSuperview];
[player autorelease];
}
任何人都可以告诉我如何获得photolibrary的路径,我需要在那里播放视频。
NSString *url = [[NSBundle mainBundle]
pathForResource:@"Stock_Footage_Demobroadband"
ofType:@"mp4"];
我们可以修改这一行,是否有任何方法可以获得照片库的路径,以便我可以在那里播放视频。帮帮我谢谢!
答案 0 :(得分:0)
您需要为UIImagePickerController实现委托方法。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *movieURL = [info objectForKey:UIImagePickerControllerMediaURL];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
//finish implementing the movie player controller
}