Question

I am using a MPMoviePlayer to stream a video URL.

The video starts in a view's frame after the user taps on it. That works ok. As the video is embedded, the default control places a Zoom in button.

When the user presses the zoom in, the video goes fullscreen ok, without interrupting playback.

However, when the user presses again the zoom out button, i have three problems:

  • The video zooms to a corner of the screen and then disappears, instead of returning to the original position.

  • The video disappears after going to the corner, and playback ends, instead of continue playing the video.

  • The MPMoviePlayerDidExitFullscreenNotification never gets called, only the MPMoviePlayerWillExitFullscreenNotification is called. I have tried sending nil and the mediaPlayerController to the notification center.

Also when pressing the Done button the video goes to the corner of the screen and disappears.

My player is created by doing:

   moviePlayer=[[MPMoviePlayerController alloc] init];
    moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
    moviePlayer.shouldAutoplay=YES;
    moviePlayer.controlStyle=MPMovieControlStyleEmbedded;
    moviePlayer.view.hidden = YES;

Then when the user taps on the view this happens:

- (void) playVideo {

    NSURL *url=[NSURL URLWithString: _news.videoUrl];

    moviePlayer.contentURL = url;
    moviePlayer.view.hidden = NO;

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

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:moviePlayer];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerDidExitFullScreen:) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer];

    [moviePlayer play];

}



- (void) moviePlayerWillExitFullScreen:(NSNotification*)notification {
    NSLog(@"WILL EXIT FULLSCREEN");

}

- (void) moviePlayerDidExitFullScreen:(NSNotification*)notification {
    NSLog(@"EXITED FULLSCREEN");  //NOT CALLED
}


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

    NSLog(@"FINISHED PLAYIIING");

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
    moviePlayer.view.hidden = YES;
}
Was it helpful?

Solution

Well, on the meanwhile I will answer 3 of my 4 questions:

  • The video zooms to a corner of the screen and then disappears, instead of returning to the original position.

  • The video disappears after going to the corner, and playback ends, instead of continue playing the video.

  • Also when pressing the Done button the video goes to the corner of the screen and disappears.

The problem was that after exiting fullscreen mode the -viewWillAppearAnimated method is called. The layout was modified in that method and that's why the playback stopped and view was sent to corner.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top