2012-10-09 87 views
0

我是一个MPMoviePlayerController,它使用默认控件在一个小框架内播放视频。如果我按下mediaplayer控件上的“全屏”按钮,一切正常 - 视频仍在播放。 视频完成后,我想关闭全屏视图并返回到非全屏视图控制器。奇怪的MPMoviePlayerController视图旋转/动画...

我的应用程序只是风景。我已经测试了“setFullscreen”属性,以在MPMoviePlayerPlaybackDidFinishNotification被调用时切换回来,该属性起作用。但是出现了从纵向到横向的视角旋转,这是错误的。我只需要景观景观。

任何想法,为什么会发生这种情况?

self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
    [self.moviePlayerController prepareToPlay]; 
    [self.moviePlayerController setShouldAutoplay:YES]; 
    self.moviePlayerController.movieSourceType = MPMovieSourceTypeFile; 

    self.moviePlayerController.fullscreen = NO; 
    self.moviePlayerController.scalingMode = MPMovieScalingModeAspectFit; 
    self.moviePlayerController.controlStyle = MPMovieControlStyleEmbedded; 

    [self.moviePlayerController.view setFrame: someMovieFrame]; 

    [tempImageScrollView addSubview:self.moviePlayerController.view]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackCompletePSV:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:self.moviePlayerController]; 
    [self.moviePlayerController play]; 



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

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

    NSLog(@"PSV moviePlaybackComplete!"); 

    // movie fadeout transition ==================== 
    self.moviePlayerController.view.alpha = 1; 

    [UIView animateWithDuration:0.3f delay:0.0 options:UIViewAnimationCurveEaseOut 
        animations:^{ 
         self.moviePlayerController.view.alpha = 0; 

         if ([self.moviePlayerController isFullscreen]) { 
          NSLog(@"PSV fullscreen movieplayer deleted"); 

          [self.moviePlayerController setFullscreen:NO animated:NO]; 
         } 
        } 
        completion:^(BOOL finished) { 
         [mymoviePlayerController stop]; 
         [mymoviePlayerController.view removeFromSuperview]; 

         [self.moviePlayerController.view removeFromSuperview]; 
         self.moviePlayerController = nil; 

        }]; 
} 

回答

0

当电影播放器​​进入全屏模式,你的父视图控制器的viewWillDisappear/viewDidDisappear被调用,当它返回到正常大小,你父视图控制器的viewWillAppear/viewDidAppear被调用。

听起来像这些方法中的某些东西无意间被调用了两次。

如果这还不足以回答您的问题,请在您的父控制器中发布适当的方法。

+0

谢谢Aaron,我只是看着父视图控制器,但viewWill/DidAppear方法中没有关于视图或大小的任何内容。我刚刚在iOS5 iPad 1上测试了应用程序。奇怪的是,在这个设备上,一切都很好 - 没有(纵向到横向)旋转。所以iOS6取决于什么?有任何想法吗? – geforce

+0

我刚刚实现了风景旋转,仅适用于包含电影播放器​​的新iOS6 VC方法“supportedInterfaceOrientations”和“preferredInterfaceOrientationForPresentation”。仍然是同样的旋转问题。希望可以有人帮帮我.. – geforce

0

iOS 6对设备的旋转和方向处理有一些改变。在此处查看更多:http://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html%23//apple_ref/doc/uid/TP40012166-CH1-SW19

首先将您的电影播放器​​支持的所有方向添加到您的.plist的字段Supported interface orientations(或创建此字段,如果错过)。

对于您的情况,您可能使用了UInavigationControllerUITabbarController作为根视图。如果是这样,让我们​​尝试继承他们并重写这些方法(如果你使用了UIViewController作为根只是覆盖它们在.m文件): :

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 
    return UIInterfaceOrientationLandscapeLeft; 
} 
- (BOOL)shouldAutorotate 
{ 
    return NO; 
} 
- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

下一页下面的​​方法添加到您的MPMoviePlayerController.m文件:

- (BOOL)shouldAutorotate{ 
    return YES; 

} 
- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskAll; 
} 

只是尝试,希望它的作品。