2011-08-11 78 views
0

對於問題標題感到抱歉。不知道怎麼稱呼它。 繼承人我的問題。我正在我的iPad應用中加載視頻。它是在一種燈箱中打開。 視頻播放正確。 現在,當我觸摸背景時,視頻應該關閉併發布,就像視頻完成時一樣(moviePlaybackComplete) 我不知道該怎麼做。繼承人我的代碼到目前爲止:強制觸發moviePlaybackComplete方法

- (IBAction)playVideo:(id)sender 
{ 
    UIButton *playButton = (UIButton *) sender; 

    NSString *filepath = [[NSBundle mainBundle] pathForResource:@"mymovie" ofType:@"mp4"]; 
    NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
    moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlaybackComplete:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:moviePlayerController]; 

    [moviePlayerController.view setFrame:CGRectMake(playButton.frame.origin.x, 
                playButton.frame.origin.y, 
                640, 
                360)]; 

    [self.view addSubview:moviePlayerController.view]; 

    [moviePlayerController play]; 
} 

- (void)moviePlaybackComplete:(NSNotification *)notification 
{ 
    MPMoviePlayerController *moviePlayerController = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:moviePlayerController]; 

    [moviePlayerController.view removeFromSuperview]; 
    [moviePlayerController release]; 
} 

- (IBAction)hideVideo:(id)sender 
{ 
    if(fadeView.hidden == NO){ 
     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:0.75]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDidStopSelector:@selector(finishedVideoFading)]; 
     fadeView.alpha = 0; 
     [UIView commitAnimations]; 

     [moviePlayerController stop]; 
     [moviePlayerController.view removeFromSuperview]; 
     [moviePlayerController release]; 
    } 
} 

回答

0

是「燈箱」一個視圖控制器?如果是,則視頻結束時關閉視圖。

[[self navigationController] popViewControllerAnimated: YES];