我正在創建MPMoviePlayerController對象並以全屏模式流式傳輸視頻。MPMoviePlayerController在單擊完成時不會刪除視圖
我使用一個UIViewController顯示短片視圖。
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
//http://www.youtube.com/watch?feature=player_detailpage&v=ebeQaznNcmE
NSURL *url = [NSURL URLWithString:@"http://a1408.g.akamai.net/5/1408/1388/2005110405/1a1a1ad948be278cff2d96046ad90768d848b41947aa1986/sample_mpeg4.mp4"];
MPMoviePlayerController *mPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
mPlayer.view.frame = gMainView.frame;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mPlayer];
mPlayer.shouldAutoplay = YES;
mPlayer.controlStyle = MPMovieControlStyleFullscreen;
[gMainView addSubview:mPlayer.view];
[mPlayer prepareToPlay];
[mPlayer setFullscreen:YES animated:YES];
[mPlayer play];
}
- (void)moviePlayBackDidFinish:(NSNotification*)notification {
int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackEnded) {
//movie finished playing
}
else if (reason == MPMovieFinishReasonUserExited) {
//user hit the done button
MPMoviePlayerController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
[moviePlayer.view removeFromSuperview];
}
[moviePlayer release];
}
else if (reason == MPMovieFinishReasonPlaybackError) {
//error
}
}
在單擊完成,視頻視覺從屏幕中刪除,但在控制不從屏幕除去視圖不從屏幕中移除。
控件確實來「//用戶點擊完成按鈕」。它確實執行代碼以從超級視圖中刪除視圖,我通過添加日誌來檢查,但是控件不會從屏幕上移除,並且視圖也不會從屏幕中刪除。 我在做什麼錯?
編輯:
如果我使用MPMoviePlayerViewController那麼它甚至沒有等我按完成。視頻完成後,它會自動刪除視圖。但我不想那樣。
編輯:
如果刪除 「[MPLAYER setFullscreen:YES動畫:是]」 然後點擊完成時,該視圖被完全去除。但是視頻並沒有全屏顯示,狀態欄變成灰色,這又是我不想要的。
你採取許多措施來形容你不想要什麼,但至少對我來說,這並還沒有真正說明你真正想要達到的目標。 – Till 2012-03-05 22:45:47
控件不會從屏幕上移除,播放器視圖也不會從屏幕上移除。 – Anand 2012-03-06 05:53:22
嘗試這種解決方案:http://stackoverflow.com/questions/6142571/mpmovieplayer-done-button-issue/6142685#6142685 – Till 2012-03-06 08:50:56