Reputation: 10083
I have an application entirely in portrait mode. (iOS 5 and above) I have a video played using MPMoviePlayerController, now in this video i want that when user rotates the iPhone, the video should go to landscape mode(in fullscreen). When video ends , again the video should go into portrait mode. Code:
-(void)PlayVideo:(NSURL*)videoUrl
{
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
[moviePlayerController.view setFrame:CGRectMake(6, 69, 309, 196)];
[self.view addSubview:moviePlayerController.view];
// moviePlayerController.fullscreen = YES;
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[self.view bringSubviewToFront:self.shareView];
[self.view bringSubviewToFront:self.qualityView];
[moviePlayerController play];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
}
Rest of the app, i want in portrait only. How do i achieve this?
Upvotes: 2
Views: 2628
Reputation: 2148
I created Xcode project with sample of the video player. It can show video on full screen in landscape mode. You can download it . I hope it helps you.
And second. Instead of
[self.view bringSubviewToFront:self.shareView];
[self.view bringSubviewToFront:self.qualityView];
you should write like this:
[moviePlayerController.view insertSubview: self.shareView
atIndex: 2];
[moviePlayerController.view insertSubview: self.qualityView
atIndex: 2];
then shareView and qualityView appears on top of the movie player.
Upvotes: 0
Reputation: 1005
First you need to set Support interface orientation to Portrait as well as Landscape
Now in every UIViewController you need to override these methods -
for iOS 5 -
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
for iOS 6
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
In UIViewController where you are going to add MPMoviePlayerController override -
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Upvotes: 4