横向模式下的iPhone MPMoviePlayer

时间:2011-02-15 13:59:39

标签: iphone mpmovieplayercontroller landscape

我希望在启动应用程序时以横向模式显示MPMoviePlayer。现在它以纵向模式启动。有些代码会强制应用程序以横向模式启动。但据说这些代码段属于私有api,因此app store不会接受该应用程序。从早上起我想找到一种方法,但没有结果......任何人都可以帮助我吗?

这就是我所在的地方:

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];

提前感谢..

3 个答案:

答案 0 :(得分:0)

在xCode中的资源组下打开项目的info.plist。 选择最后一行并单击+(加号)图标。现在为值'Landscape(左主页按钮)'选择“初始界面方向”键。 或者您可以从单击下拉按钮上显示的列表中选择任何值。

答案 1 :(得分:0)

如果您的所有应用都将在风景中,您可以在项目的plist中更改它。如果没有,你也可以继承MPMoviePlayerControllerView并实现并执行类似的操作。

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

  return NO;
}

答案 2 :(得分:0)

使用MPMoviePlayerViewController代替MPMoviePlayerController。它将处理方向,控制风格等。我提到https://stackoverflow.com/a/4911172/3346048也是如此。

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

并在AppDelegate.m中声明以下函数。在所有情况下都会将方向限制为纵向,并且只会在播放视频时更改:

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

}