After exiting the full screen MPMoviePlayerController set the zoom mode to MPMovieScalingModeFill in ios

In my application, I play video using mpmovieplayercontroller

first set the zoom mode to MPmovieScalingmodefill and display the video correctly for scaling.

then after I watch the video in full screen mode and exit full screen mode, then do not set the zoom mode to MPmovieScalingmodeFill and display the video in defualt mode.

below my code to play video

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil]; [appDelegate.moviePlayerController setContentURL:fileURL]; if ([appDelegate checkDevice]) { [appDelegate.moviePlayerController.view setFrame:CGRectMake(0,0, 320,463)]; } else { [appDelegate.moviePlayerController.view setFrame:CGRectMake(0,0, 320,375)]; } [appDelegate.moviePlayerController prepareToPlay]; appDelegate.moviePlayerController.scalingMode=MPMovieScalingModeFill; appDelegate.moviePlayerController.controlStyle=MPMovieControlStyleDefault; appDelegate.moviePlayerController.shouldAutoplay=NO; [appDelegate.moviePlayerController setFullscreen:YES animated:YES]; [appDelegate.moviePlayerController play]; [self.view addSubview:appDelegate.moviePlayerController.view]; - (void)ExitFullScreen:(NSNotification *)notification{ NSLog(@"Exit full Screen"); [appDelegate.moviePlayerController setControlStyle:MPMovieControlStyleEmbedded]; [appDelegate.moviePlayerController setScalingMode:MPMovieScalingModeFill];} 

so my problem is how to set the zoom mode after exiting the full screen or not changing the zoom mode after the exit screen?

please help me.

thanks.

+4
source share
2 answers

This is not an β€œideal” solution, but it works! Basically, as soon as you exit full-screen mode, the MPMoviePlayerController instance gets all hovering and resetting the scaling property in MPMovieScalingModeFill will not help no matter where and when you do it (I tried all kinds of things and gave up after an hour). The simplest solution is to remove MPMoviePlayerController and just select a new instance of MPMoviePlayerController every time a full screen comes out (not perfect, but works completely):

 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:NO]; if (self.moviePlayer != nil) [self.moviePlayer.view removeFromSuperview]; self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:self.videoURL]; self.moviePlayer.view.frame = CGRectMake(#, #, #, #); self.moviePlayer.movieSourceType = MPMovieSourceTypeFile; self.moviePlayer.shouldAutoplay = NO; [self.moviePlayer setContentURL:self.videoURL]; [self.moviePlayer prepareToPlay]; [self.moviePlayer setScalingMode:MPMovieScalingModeFill]; [self.view addSubview:self.moviePlayer.view]; } 

PS: Do not forget to call super viewDidAppear or suffer all kinds of unforeseen chaos (a very common mistake in iOS development)

0
source

I believe this will generate MPMoviePlayerScalingModeDidChangeNotification .

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieScalingModeDidChange:) name:MPMoviePlayerScalingModeDidChangeNotification object:nil]; 

MPMoviePlayerScalingModeDidChangeNotification

Sent when the zoom mode of the video player has changed. There is no user information dictionary. The zoom mode can be changed programmatically or by interacting with the user. To set or get the zoom mode of the video player, open its scalingMode property. A movie player whose state has changed is available as an object associated with the notification.

0
source

Source: https://habr.com/ru/post/1496089/


All Articles