Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

iphone - How To Rotate An MPMoviePlayerController

I am building an iPhone app that plays videos on demand from a web service.

The videos play in an MPMoviePlayerController, and everything works fine on the iPhone device.

However, when one loads up the iPhone application on an iPad, the videos play Portrait mode (with letterboxing on the top and bottom), instead of Landscape Left like they do on the iPhone.

At first the videos were not appearing at all, however I fixed this by adding the MPMoviePlayerControllers view to the view that is creating it, as a subview, and then set it to play fullscreen.

--

Edit To Original:

I now have it playing on the iPad in all rotations. Is there any way to stop it rotating, and just have it play LandscapeLeft?

Thanks, Dwaine

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

iPad apps are supposed to support all four interface orientations.

EDIT: I haven't managed to find official docs to cite. It might be simply that iPad apps are supposed to be able to launch in all orientations, though you can force some bits to be landscape if it's "sensible". Whether Apple rejects your app or not is another issue, but I think they're unlikely to reject a video app that plays video in landscape.

After some experimentation, the following seems to work:

@interface MyMovieViewController : MPMoviePlayerViewController
@end

@implementation MyMovieViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

@end

Then just instantiate MyMovieViewController instead of MPMoviePlayerViewController.

EDIT 2: MPMoviePlayerViewController is not the same as MPMoviePlayerController; you use it to get the behaviour of the 2.0-3.1 MPMoviePlayerController. You need to add the view controller to the VC hierarchy, but it's pretty simple (and a lot easier than messing around with view transforms):

MPMoviePlayerViewController * vc = [[MyMovieViewController alloc] initWithContentURL:aUrl];
[self presentMoviePlayerViewControllerAnimated:vc];
[vc.moviePlayer play];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...