【问题标题】:Why isn't the scalingMode of my MPMoviePlayerController being respected when coming back from Full Screen?为什么从全屏返回时我的 MPMoviePlayerController 的 scalingMode 不被尊重?
【发布时间】:2014-06-20 13:30:26
【问题描述】:

我有一个 MPMoviePlayerController 实例,当我第一次将 iPhone 旋转到横向模式时,它可以在纵向模式和全屏模式下正确显示 HLS 视频流。当我从全屏返回时会出现问题:我的 MPMoviePlayerController 的 scalingMode 属性仍设置为 MPMovieScalingModeAspectFill,但视频显示为设置为 MPMovieScalingModeAspectFit。

在将其视图添加为我的视图 (self.movi​​eView) 的子视图 (self.movi​​ePlayer.view) 之前,我将它的 scalingMode 设置为 MPMovieScalingModeAspectFill 并且一切正常,直到我退出全屏。

- (void) play
{
    self.moviePlayer = [[MPMoviePlayerController alloc] init];

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

    self.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    self.moviePlayer.contentURL = videoURL;
    self.moviePlayer.controlStyle = MPMovieControlStyleNone;
    self.moviePlayer.shouldAutoplay = YES;
    self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
    NSLog(@"%ld", (long) self.moviePlayer.scalingMode);

    self.moviePlayer.view.frame = CGRectMake(0, 0, 320, 180);

    [self.movieView addSubview:self.moviePlayer.view];

    [self.moviePlayer setFullscreen:NO animated:NO];
}

当我从全屏返回时,它被设置为默认值 (MPMovieScalingModeAspectFit),即使我在收到 MPMoviePlayerScalingModeDidChangeNotification 时明确尝试,我也无法将其更改回 MPMovieScalingModeAspectFill。

- (void)movieScalingModeDidChange:(NSNotification *)notification
{
    self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
    NSLog(@"%ld", (long) self.moviePlayer.scalingMode);
}

奇怪的是,这个 NSLog 给了我:

-[CameraViewController play]:2

根据文档,这是 MPMovieScalinModeAspectFill 的枚举,但视频不是此方面模式。

typedef enum {
   MPMovieScalingModeNone,
   MPMovieScalingModeAspectFit,
   MPMovieScalingModeAspectFill,
   MPMovieScalingModeFill
} MPMovieScalingMode;

有没有人遇到过同样的问题?提前致谢!

【问题讨论】:

    标签: ios objective-c mpmovieplayercontroller fullscreen scaling


    【解决方案1】:

    从我在其他几个问题herehere 中看到的情况来看,当 MPMoviePlayerController 从全屏返回时,它似乎真的搞砸了,解决方法是从视图中删除其元素并将其添加回来再次使用所需的 scalingMode。好吧,我不希望重新加载我的流,因为缓冲有时可能需要很长时间,这真的会影响用户体验。

    这就是我所做的。我在加载视图时将 scalingMode 设置为其默认值,并添加了一个“调整大小”按钮,当用户单击它时会更改此属性(我记得一些用户说我们在移动设备上“省略了”图像的重要部分)。现在当用户旋转 iPhone 时,它​​会保持所需的缩放模式,当它返回到纵向模式时,它将被设置为默认模式。

    我希望这可能对面临相同问题的任何人有所帮助。

    【讨论】:

      【解决方案2】:

      您需要将scalingMode 更改为MPMovieScalingModeAspectFill 以外的任何值,并在接收MPMoviePlayerScalingModeDidChangeNotification 时再次设置宽高比

      - (void)playerDidExitFullscreen:(NSNotification *)notification
      {
          self.moviePlayer.scalingMode = MPMovieScalingModeNone;
          self.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
      }
      

      它适用于微小的动画问题。

      【讨论】:

        猜你喜欢
        • 2013-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-17
        • 2019-03-14
        • 1970-01-01
        • 2017-06-01
        • 1970-01-01
        相关资源
        最近更新 更多