开发者

iPhone forcing orientation after video playback

I have a problem which is doing my head in and should be so simple to resolve. Here is my code:

-(IBAction)playMovie:(id)sender{

    NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"myMovie" ofType:@"MOV"];  
    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];  
    moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];  

    [[NSNotificationCenter defaultCenter] addObserver:self  
                                             selector:@selector(moviePlaybackComplete:)  
                                                 name:MPMoviePlayerPlaybackDidFinishNotification  
                                               object:moviePlayerController];  

    [self.view addSubview:moviePlayerController.view];  
    //[moviePlayerController setOrientation:UIInterfaceOrientationLandscapeLeft];
    moviePlayerController.fullscreen = YES;  
    moviePlayerController.scalingMode = MPMovieScalingModeFill;    

    [moviePlayerController play]; 

}

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

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrienta开发者_开发知识库tionPortrait];

    moviePlayerController = [notification object];  
    [[NSNotificationCenter defaultCenter] removeObserver:self  
                                                    name:MPMoviePlayerPlaybackDidFinishNotification  
                                                  object:moviePlayerController];  

    [moviePlayerController.view removeFromSuperview];  
    [moviePlayerController release];  
}  

And the orientation:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
        return(YES);
    }

    if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        return([moviePlayerController isFullscreen]);
    }




    return(NO);

}

This works as desired at first. The orientation is initially forced to portrait, then the movie plays and landscape allows the movie to rotate and be viewed in landscape. Then after done is clicked and the movie is finished the interface is left in landscape. I need it to be forced back to portrait mode... i've seen solutions like

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

which now seems to be deprecated as of ios 4.0

Ideally as soon as the movie finished method fires it should auto rotate to portrait!

any solutions?


Try this:

[[NSNotificationCenter defaultCenter] addObserver:self  
                                         selector:@selector(moviePlaybackComplete:)  
                                         name:MPMoviePlayerWillExitFullscreenNotification  
                                         object:moviePlayerController];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜