简体   繁体   中英

After exit full screen MPMoviePlayerController set scaling mode to MPMovieScalingModeFill in ios

In my application i play video using mpmovieplayercontroller

first set scaling mode to MPmovieScalingmodefill and display video correct to scalingmode.

then after i view video in full screen and exit full screen then not set scaling mode to MPmovieScalingmodeFill and display video in defualt mode.

below my code for video playing

[[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 probleem is how can set scaling mode after exit full screen or do not change scaling mode after exit screen ?

please help me out.

thanks.

I believe this will generate the MPMoviePlayerScalingModeDidChangeNotification .

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

MPMoviePlayerScalingModeDidChangeNotification

Posted when the scaling mode of a movie player has changed. There is no userInfo dictionary. Scaling mode can change programmatically or by user interaction. To set or retrieve the scaling mode of a movie player, access its scalingMode property. The movie player whose state has changed is available as the object associated with the notification.

This isn't the "ideal" solution, but it works! Basically, once you exit full screen the MPMoviePlayerController instance gets all screwed up and resetting the scaling property to MPMovieScalingModeFill won't help no matter where or when you do it (I've tried all sorts of stuff and after an hour gave up). Easiest solution is to remove the MPMoviePlayerController and simply allocate a new instance of MPMoviePlayerController each time full screen is exited (not ideal, but totally works):

- (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: Don't forget to call super's viewDidAppear or suffer all sorts of unforeseeable mayhem (a very common mistake in iOS development)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM