0

I want to show an MPMoviePlayer in landscape mode on launch of the application. Now it starts in portrait mode. There are some codes which forces application to launch in landscape mode. But it is said that these code segments belong to private api so app store will not accept the application. Since morning I am trying to find a way, but no result... Can anyone help me?

This is where I am:

NSURL *url = [[NSURL alloc] initWithString:urlString];

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(videoPlayerPlaybackStateChanged:) 
                                             name:MPMoviePlayerPlaybackStateDidChangeNotification
                                           object:nil];

[self setWantsFullScreenLayout:YES];
[moviePlayer prepareToPlay];
//For viewing partially.....
moviePlayer.view.backgroundColor = [UIColor blackColor];
//[moviePlayer.view setFrame:CGRectMake(0, 0, 320, 410)];
[moviePlayer.view setFrame:[self.view bounds]];
moviePlayer.fullscreen = YES;
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;


[self.view addSubview:moviePlayer.view]; 

//[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
[moviePlayer play];

Thank in advance..

gurkan
  • 3,457
  • 4
  • 25
  • 38

3 Answers3

0

Use MPMoviePlayerViewController instead of MPMoviePlayerController. It will handle orientation, control style etc. I referred https://stackoverflow.com/a/4911172/3346048 for the same.

MPMoviePlayerViewController *playerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:playerView];

and in the AppDelegate.m declare the following function. Which will restrict the orientation to portrait in all cases and will only change when a video is playing:

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
    {
        return return UIInterfaceOrientationMaskLandscape;
    }

}
Community
  • 1
  • 1
sonal
  • 21
  • 3
0

Open your project's info.plist under the Resource group in xCode. select last line and click on the +(plus) icon. Now select the key 'Initial interface orientation' for value 'Landscape (left home button)'. or you can select any value from the list shown on clicking drop down buttons.

Rajender Kumar
  • 1,377
  • 19
  • 32
  • Thank you for the quick answer but I have tried it. Simulator gets back to portrait mode again. I didn't get the reason.. – gurkan Feb 15 '11 at 15:07
0

If all your app is gonna be in landscape you can change it at your project's plist. If not, you can also subclass MPMoviePlayerControllerView and implement and do something like this.

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

  return NO;
}
Yorxxx
  • 526
  • 4
  • 9
  • Ok. Thank you. This one works fine. But when i pass this viewController to navigationController, i mean [self.navigationController pushViewController: "bla bla"] , after getting back from the next view its orientation is still landscape but content inside view is now portrait. Buy the way, next view after MPMoviePlayerView is portrait. – gurkan Feb 15 '11 at 15:10