横向模式下的 iPhone MPMoviePlayer
我想在启动应用程序时以横向模式显示 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 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.
如果您的所有应用程序都是横向的,您可以在项目的 plist 中更改它。如果没有,您也可以子类 MPMoviePlayerControllerView 并实现并执行类似的操作。
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.
使用
MPMoviePlayerViewController
而不是MPMoviePlayerController
。它将处理方向、控制风格等。我提到了https://stackoverflow.com/a/4911172/3346048相同的。并在
AppDelegate.m
中声明以下函数。这将在所有情况下将方向限制为纵向,并且仅在视频播放时才会更改:Use
MPMoviePlayerViewController
instead ofMPMoviePlayerController
. It will handle orientation, control style etc. I referred https://stackoverflow.com/a/4911172/3346048 for the same.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: