2011-03-16 70 views
2

我試圖通過單擊按鈕啓動電影。當我點擊電影播放器​​出現並工作正常。電影一直播放到最後,電影播放器​​消失。它消失後,我的應用程序崩潰...當我的電影完成播放時,應用程序崩潰

我用在標籤欄的應用我的視圖控制器,此代碼:

- (void)moviePlayBackDidFinish:(NSNotification *) aNotification{ 

    MPMoviePlayerController *player = [aNotification object]; 
    [player setFullscreen:NO animated:YES]; 
    [player.view removeFromSuperview]; 
    [player stop]; 
    player.initialPlaybackTime = -1.0; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player]; 
    [player release]; 
    player=nil; 
} 

- (IBAction)playVideo:(UIButton *)playButton{ 
    NSString *url = [[NSBundle mainBundle] pathForResource:@"Teaser 04" ofType:@"mov"]; 
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; 
    player.shouldAutoplay = YES; 
    player.view.frame = CGRectMake(0., 44., self.view.bounds.size.width, self.view.bounds.size.height-44); 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:player]; 
    [self.view addSubview:player.view]; 
    [player play]; 
} 

我不知道我做錯了。我只是想設置一個按鈕,開始播放視頻,並在視頻結束時,MoviePlayer查看消失,應用回到我最初的.xib

謝謝您的幫助

回答

1

我找到了解決辦法,我不知道這是否是最好的,但什麼我想它的工作:

- (void)movieFinishedCallBack:(NSNotification *) aNotification{ 
MPMoviePlayerController *player = [aNotification object]; 
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player]; 
[player.view removeFromSuperview]; 
[player stop]; 
[player release]; 

}

- (IBAction)playVideo:(UIButton *)playButton{ 
NSString *url = [[NSBundle mainBundle] pathForResource:@"Teaser 04" ofType:@"mov"]; 
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallBack:) name:MPMoviePlayerPlaybackDidFinishNotification object:player]; 
player.view.frame = CGRectMake(0, 0, 950, 600); 
[self.view addSubview:player.view]; 
[player play]; 

}

0

我可能是錯的,但我的猜測是玩家會在回溯到moviePlayBackDidFinish的地方的某個地方使用:...如果我是對的,那麼在那裏釋放對象 - 看起來好像你在做什麼 - 是壞消息,因爲對象是仍然需要在堆棧中的某個地方。

退房這個職位的詳細信息:How to release MPMoviePlayerController?

+0

感謝您的鏈接,但這不是關於此。我通過movieFinishedCallBack切換功能moviePlayBackDidFinish – Mitch 2011-03-16 20:16:30

+0

他不是釋放播放器,而是釋放它。 – Till 2011-03-31 09:25:43

+0

他不是通過在那裏調用「release」來有效地釋放它嗎? – 2011-04-06 21:03:08

相關問題