横向模式下的 iPhone MPMoviePlayer

发布于 2024-10-17 18:25:28 字数 1178 浏览 7 评论 0原文

我想在启动应用程序时以横向模式显示 MPMoviePlayer。现在它以纵向模式启动。有一些代码强制应用程序以横向模式启动。但据说这些代码段属于私有api,所以应用商店不会接受该应用。从早上开始我就试图找到一种方法,但没有结果......有人可以帮助我吗?

这就是我所在的位置:

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

提前谢谢..

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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

澉约 2024-10-24 18:25:29

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

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.

熊抱啵儿 2024-10-24 18:25:29

如果您的所有应用程序都是横向的,您可以在项目的 plist 中更改它。如果没有,您也可以子类 MPMoviePlayerControllerView 并实现并执行类似的操作。

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

  return NO;
}

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;
}
人海汹涌 2024-10-24 18:25:29

使用 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;
    }

}

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文