2012-04-04 118 views
0

我正在做一個應用程序在ipad上,它將捕獲視頻,它將保存在照片庫中。但我想要的是我想播放該視頻從照片庫中選擇,並需要在那裏播放。我看到很多使用MPMoviePlayerController的例子,但我看到的是他們在那裏添加視頻,他們播放該視頻。有沒有辦法爲我下面提到的代碼寫道。 我的代碼放在這裏如何通過從PhotoLibrary獲取視頻播放視頻

這其中我打電話的照片庫

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

任何一個可以告訴我,我怎樣才能得到路徑photolibrary我需要在那邊播放視頻。

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

我們可以修改這條線上,有什麼辦法,我可以得到路徑的照片庫,這樣我可以在那裏玩視頻。幫助我謝謝!

回答

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 

} 
+0

感謝,但我之前這種方法實現.. – Kiran 2012-04-04 09:08:52

+0

u能告訴我,我們可以改變這一行,是有,我們可以通過更換這行 – Kiran 2012-04-04 09:09:51

+0

的NSString * URL = [[一個NSBundle寫照片庫路徑任何方式mainBundle] pathForResource:@「Stock_Footage_Demobroadband」 ofType:@「mp4」]; – Kiran 2012-04-04 09:10:33