2012-12-20 85 views
6

MPMoviePlayerController播放器在完成按鈕後隱藏播放器控件。MPMoviePlayerController:播放器只在播放時隱藏播放器控件iOS6

我有一個帶有moviePlayer.controlStyle = MPMovieControlStyleEmbedded的嵌入式播放器,當用戶在全屏模式下點擊moviePlayerDidEnterFullscreen通知時,我正在製作[moviePlayer setFullscreen:NO];和改造播放器的視頻爲橫向模式

moviePlayer.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); 

和設置

moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 

然後當我點擊完成按鈕,並在moviePlayBackDidFinish我正在轉化視圖返回到肖像模式和設置controlStyle嵌入式。到目前爲止它的工作正常。之後,視頻將暫停,當我點擊播放按鈕時,其開始播放和播放器將停留一段時間並永久隱藏。在錄製視頻後播放器不再可見。我試圖在延遲後將播放器控件設置爲嵌入。但沒有任何工作。請幫助解決這個問題。

這個問題只在以下版本的iOS 6

代碼

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

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlayerDidEnterFullscreen:) 
              name:MPMoviePlayerDidEnterFullscreenNotification 
              object:nil]; 


if (mpVideoPlayerController) 
{ 
    [mpVideoPlayerController.moviePlayer pause]; 
    [mpVideoPlayerController.moviePlayer stop]; 
} 


mpVideoPlayerController = nil; 
mpVideoPlayerController = [[VideoPlayerViewController alloc] initWithContentURL: theURL]; 


mpVideoPlayerController.moviePlayer.movieSourceType = liveStreaming ? MPMovieSourceTypeStreaming : MPMovieSourceTypeUnknown; 

if ([mpVideoPlayerController.moviePlayer respondsToSelector:@selector(setAllowsAirPlay:)]) { 
    mpVideoPlayerController.moviePlayer.allowsAirPlay = YES; 
} 

[[mpVideoPlayerController.moviePlayer view] setFrame:viewInsetRect]; 
mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleEmbedded; 
mpVideoPlayerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
[viewController.view addSubview: [mpVideoPlayerController.moviePlayer view]]; 
[mpVideoPlayerController.moviePlayer play]; 
} 


-(void) moviePlayerDidEnterFullscreen :(NSNotification*)notification { 
    [mpVideoPlayerController.moviePlayer setFullscreen:NO]; 
    [[UIApplication sharedApplication] setStatusBarHidden:YES]; 
    [self performSelector:@selector(setControlStyleFullscreen) withObject:nil afterDelay:0.2]; 
    [UIView animateWithDuration:0.3 
        animations:^{ 
         mpVideoPlayerController.moviePlayer.view.transform = CGAffineTransformIdentity; 
         mpVideoPlayerController.moviePlayer.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); 
         CGRect frame=[[UIScreen mainScreen] applicationFrame]; 
         frame.origin.y=-20; 
         mpVideoPlayerController.moviePlayer.view.frame = frame;//CGRectMake(0.0, 0.0, 480.0, 300.0); 
        } completion:^(BOOL finished) { 

        }]; 


} 

- (void) setControlStyleFullscreen 
     mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 

- (void) setControlStyleEmbedded 

     mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleEmbedded; 



- moviePlayBackDidFinish: 

    NSLog(@"moviePlayBackDidFinish:"); 

    [self rotateToInterfaceOrientation:UIInterfaceOrientationPortrait frameForView:(viewController).videoContentView.frame]; 

    [[UIApplication sharedApplication] setStatusBarHidden:NO]; 

    [self performSelector:@selector(setControlStyleEmbedded) withObject:nil afterDelay:0.2]; 
+1

分享您使用的MPmoviecontroller的完整代碼... – Vishal

+1

感謝Vishal,請檢查代碼 –

回答

1

你的代碼是怎麼樣的故障,並觸發這些MPMoviePlayerController錯誤。

  • 多餘的setFullscreen,因爲我們已經在全屏。
  • 多餘setControlStyle,因爲我們已經在控制風格全屏

一般來說,你不應該強制執行的MPMoviePlayerController事情都已經做了。

- (void)moviePlayerDidEnterFullscreen :(NSNotification*)notification 
{ 
    // 
    //remove both lines from this notification handler 
    // 
    [mpVideoPlayerController.moviePlayer setFullscreen:NO]; 
    [self performSelector:@selector(setControlStyleFullscreen) withObject:nil afterDelay:0.2]; 
    [...] 
} 

你也可以通過檢查當前模式來擴展你的setControlStyleFullscreen/Embedded實現。這看起來很奇怪,但確實有很大的幫助。

- (void)setControlStyleEmbedded 
{ 
    if (mpVideoPlayerController.moviePlayer.controlStyle != MPMovieControlStyleEmbedded) 
    { 
     mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleEmbedded; 
    } 
} 

- (void)setControlStyleFullscreen 
{ 
    if (mpVideoPlayerController.moviePlayer.controlStyle != MPMovieControlStyleFullscreen) 
    { 
     mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 
    } 
}