0

我有一个 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;

                    }];
}
4

2 回答 2

0

当电影播放器​​全屏时,你的父视图控制器的viewWillDisappear/viewDidDisappear被调用,当它恢复正常大小时,你的父视图控制器的viewWillAppear/viewDidAppear被调用。

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

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

于 2012-10-09T15:38:33.207 回答
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

首先将您的电影播放器​​需要支持的所有方向添加到Supported interface orientations您的.plist.

在您的情况下,也许您使用UInavigationControllerorUITabbarController作为根视图。如果是这样,让我们​​尝试对它们进行子类化并覆盖这些方法(如果您使用 aUIViewController作为根,只需在.m文件中覆盖它们)::

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

接下来将以下方法添加到您MPMoviePlayerController.m文件中:

- (BOOL)shouldAutorotate{
    return YES;

}
- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}

只是尝试,希望它有效。

于 2012-10-11T03:40:32.840 回答