0

我正在 ipad 上做一个应用程序,它将捕获视频并将保存在照片库中。但我想要的是我想播放从照片库中选择的视频并需要在那里播放。我看到了很多使用的例子,MPMoviePlayerController但我看到的只是他们在那里添加视频并播放那个视频。有什么办法可以写我下面提到的代码的路径。我的代码在这里

这是我调用照片库的地方

-(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。代码在这里

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

谁能告诉我如何获得照片库的路径,我需要在那里播放视频。

 NSString *url = [[NSBundle mainBundle]
                         pathForResource:@"Stock_Footage_Demobroadband"
                         ofType:@"mp4"];

我们可以修改这条线吗?有什么方法可以让我获得照片库的路径,以便我可以在那里播放视频。帮帮我谢谢!!

4

1 回答 1

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

}
于 2012-04-04T09:06:37.693 回答