简体   繁体   中英

iPhone SDK 4: video autorotation from MPMoviePlayerViewController

Could you please show an example of shouldAutorotateToInterfaceOrientation method usage as a part of MPMoviePlayerViewController? As far as I know, using shouldAutorotateToInterfaceOrientation method is available not only for UIView but also for MPMoviePlayerViewController since SDK 3.2. I've been using it in UIView, in 3.1, but I don't understand how to use it in MPMoviePlayerViewController class.

This is what I have for now:

-(IBAction) playMovie {

//declaring path to file and stuff...

    MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

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

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

        MPMoviePlayerController *player = [playerViewController moviePlayer];
        [self.view addSubview:playerViewController.view];
        player.controlStyle = MPMovieControlStyleDefault;
        player.shouldAutoplay = YES;
        [player setFullscreen:YES animated:YES];
    } 

    - (void)moviePlayBackDidFinish:(NSNotification*)notification {
        MPMoviePlayerViewController *moviePlayer = [notification object];
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:MPMoviePlayerPlaybackDidFinishNotification
                                                      object:moviePlayer];

        [moviePlayer.view removeFromSuperview];

        [moviePlayer release];  
    }

It works just fine but I need to know how to implement video autorotation. The method used for it in UIView does not help.

Thanks.

Hm, sounds strange but I was sure this method must not be declared ouside playMovie block. I was wrong, the following code is pasted as usual and it does what I need.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    if (interfaceOrientation == UIInterfaceOrientationPortrait ||
        interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        interfaceOrientation == UIInterfaceOrientationLandscapeRight)
        return YES;
    else {
        return NO;
    }

}

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