2012-10-16 59 views
0

我需要從View中刪除MPMoviePlayerController。 我試過了。無法使用removeFromSuperView刪除MPMoviePlayerController

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

視頻停止,但視圖不會被刪除。我猜[moviePlayerController.view removeFromSuperview];不起作用。可能是什麼原因 ?任何解決這個問題..?

謝謝。

+0

請張貼有關加入moviePlayer試了試視圖 –

回答

0

不完全確定,但由於我有電影播放器​​因爲自動釋放而沒有顯示出來的問題,我猜你可以設置moviePlayerController = nil;

不完全確定視圖是否會消失,但值得一試!

+0

..但沒有工作的代碼.. :( –

+0

難道你已經有movieController視圖裏面?試試'[viewContainingMovieController removeFromSuperview] ;' – Tom

0

嘗試dismissViewController:animated:這可能會起作用。

0
[moviePlayerController stop]; 
[moviePlayerController setContentURL:nil]; 
[moviePlayerController.view removeFromSuperview]; 

,這是在我的項目

0

運行良好對我來說,我嘗試了所有的這些: [moviePlayer stop]; [moviePlayer setContentURL:nil]; [moviePlayer.view removeFromSuperview]; moviePlayer = nil;

並沒有什麼工作。我想通過我的MPMoviePlayerController進入全屏幕,它已經到期了。修復?

 [moviePlayer setFullscreen:NO animated:YES]; 
1

它是一個已知的問題,您正在使用ARC該ID,那麼你必須給玩家添加到您的.h因爲,如果你在本地聲明它仍然得到釋放。

@property (nonatomic, strong) MPMoviePlayerController* controller; 

要添加視圖:

self.controller = [[MPMoviePlayerController alloc] initWithContentURL:YOURVIDEOURL]; 

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlayBackDidFinish:) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:self.controller]; 

self.controller.controlStyle = MPMovieControlStyleDefault; 
self.controller.shouldAutoplay = YES; 

[self.view addSubview:self.controller.view]; 
[self.controller setFullscreen:YES animated:YES]; 

然後刪除視圖:

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

if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) 
{ 

    [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO]; 

} 

MPMoviePlayerController *player = [notification object]; 
[[NSNotificationCenter defaultCenter] 
removeObserver:self 
name:MPMoviePlayerPlaybackDidFinishNotification 
object:player]; 

if ([player 
    respondsToSelector:@selector(setFullscreen:animated:)]) 
{ 
    [player.view removeFromSuperview]; 
} 
} 
1

這個問題通常是由於玩家的獲得deallocated.The的解決方案是,聲明播放器實例在與財產「強」的.h。

@property (nonatomic,strong) MPMoviePlayerController* mpController;