2
votes

I have an instance of MPMoviePlayerController that is correctly displaying a HLS video stream on Portrait mode and also on Full Screen when I rotate my iPhone to the Landscape mode for the first time. The issue happens when I come back from Full Screen: the scalingMode property of my MPMoviePlayerController is still set to MPMovieScalingModeAspectFill but the video is displayed as it is set to MPMovieScalingModeAspectFit.

Before adding its view as a Subview (self.moviePlayer.view) of my View (self.movieView) I set its scalingMode to MPMovieScalingModeAspectFill and everything works fine untill I exit Full Screen.

- (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];
}

When I return from Full Screen it is set to the default value (MPMovieScalingModeAspectFit) and I can't change it back to MPMovieScalingModeAspectFill even if I explicity try to when I receive the MPMoviePlayerScalingModeDidChangeNotification.

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

The weird thing is that that this NSLog gives me:

-[CameraViewController play]:2

Which according to the Documentation is the enum for MPMovieScalinModeAspectFill, but the video is not it this aspect mode.

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

Has anyone experienced this same issue? Thanks in advance!

2

2 Answers

0
votes

You need change scalingMode to any value other than MPMovieScalingModeAspectFill and set aspect fit again on receiving MPMoviePlayerScalingModeDidChangeNotification

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

It works with tiny animation issue.

0
votes

From what I have seen in a couple of other questions here and here it really seems that MPMoviePlayerController gets screwed when it comes back from full screen and the workaround is to remove its element from the view and add it back again using the desired scalingMode. Well, I don't want my stream to be reloaded since buffering might take too long sometimes and this really kills the user experience.

So here is what I did. I set the scalingMode to its default value when the view is loaded and added a "resize" button that changes this property when the user clicks it (I remembered some users saying that we were "leaving out" important parts of the image on the mobile). Now when the user rotates its iPhone it will remaing with the desired scalingMode and when it returns to the Portrait mode, it will be set as the default.

I hope this may be of help to anyone facing the same issue.