我有很多在我的iPad應用程序顯示一個全屏電影麻煩,然後允許用戶無論使用哪種完成按鈕或「非全屏」予以駁回播放器控制按鈕。正確顯示和iOS 3.2(iPad版)駁回全屏的MPMoviePlayerController
起初,我使用MPMoviePlayerViewController
爲電影的介紹,但我並沒有從MPMoviePlayerController
對象接收的進入/退出全屏通知,所以我切換到做我自己。
我可以讓電影全屏顯示(雖然過渡很快),但當按下「完成」或「非全屏」按鈕時,播放器不採取任何操作。我已爲我下面的代碼:
- (void)startPlayingMovieWithURLString:(NSString *)movieURLString {
// I get all of these callbacks **EXCEPT** the "willExitFullScreen:" callback.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.moviePlayerController setContentURL:someExistingURL];
// "self" is a UIViewController subclass, and is presented as a "fullscreen" modal view controller from its parent
// I'm setting the movie player's view's frame to take up the full rectangle of my view controller, but really I want the movie to be completely removed when the user presses "done" (that is, removed from the view hierarchy). Not sure when/where to do this.
self.moviePlayerController.view.frame = self.view.frame;
[self.view addSubview:self.moviePlayerController.view];
[self.moviePlayerController setFullscreen:YES animated:YES];
}
這裏是我的didFinish回調
- (void)didFinishPlayback:(NSNotification *)notification {
// This ends up recursively telling the player that playback ended, thus calling this method, thus…well you get the picture.
// What I'm trying to do here is just make the player go away and show my old UI again.
[self.moviePlayerController setFullscreen:NO animated:YES];
}
所以,很顯然,我做錯了什麼,但我已經起來的文檔,我下來的代碼無法弄清楚如何讓電影消失。我認爲這會比這更直觀。我究竟做錯了什麼?
這是有幫助的,我現在可以在用戶按下完成時退出全屏,但-playbackFinished:回調從來沒有爲我執行過,我不能爲我的生活找出原因。你知道這有可能發生的原因嗎? – jbrennan 2010-07-15 02:43:46
即使電影玩到最後?奇怪的是,我從來沒有遇到過這種情況。 – 2010-07-15 03:49:53
如果在觸摸「完成」和全屏退出時調用MPMoviePlayerDidExitFullscreenNotification,您怎麼知道哪個被調用?也許用戶只能退出全屏,在這種情況下,你不想刪除我猜測的視圖。 – 2011-06-10 13:07:44