MPMoviePlayerController : orientation problem

2019-04-16 04:37发布

问题:

finally I have to post my problem here. Yes it could be duplicate question here as I have referred many answers regarding to this question.But I could not find any fix. (Also didn't find any question regarding to tab-bar app specific so...) And I don't want to use MPMoviePlayerViewController

I have tab-bar application. In last tab's VC there is a button. On click event I want to start movie player. For that I am using MPMoviePlayerController. Its all fine when orientation is Portrait . But regarding to changes, now I have to play it in landscape mode only.

here is my code :

-(void)playMovie
{
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    [self.scrollView addSubview:moviePlayer.view];

    [moviePlayer play];
    [moviePlayer setFullscreen:TRUE];
}
-(void)btnPlayHandler:(id)sender
{   
    NSLog(@"btnPlayHandler");

    NSURL * videoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[dictResponse valueForKey:@"VideoPath"]]];
    moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:videoUrl];
    //[moviePlayer.view setFrame:CGRectMake(20, 40, 280, 222)]; 
    moviePlayer.fullscreen = YES ;
    moviePlayer.shouldAutoplay = NO ;

    [self performSelector:@selector(playMovie) withObject:nil afterDelay:1];    
}

- (void) movieWillExit:(NSNotification *)notification
{
    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
}

- (void) movieExit:(NSNotification *)notification
{
    [moviePlayer stop];
    [moviePlayer.view removeFromSuperview];
    moviePlayer = nil ;

    [btnPlay setHidden:FALSE];
}

- (void)moviePreLoad:(NSNotification *)notification  
{
    NSLog(@"moviePreLoad");
}

- (void)moviePlaybackComplete:(NSNotification *)notification  
{  
    NSLog(@"moviePlaybackComplete");
    [btnPlay setHidden:FALSE];
} 

Only device's orientation is changed not player's view ! How to accomplish this ??? Is it because the tab-bar application ?

回答1:

You are making the window landscape, but as you have set the MPMoviePlayer view in scrollview, it is not rotating. try to rotate the scrollview according to your orientation. See this link http://blog.sallarp.com/shouldautorotatetointerfaceorientation/. Hopefully it will solve your problem.