首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MPMoviePlayerController的集定向

MPMoviePlayerController的集定向
EN

Stack Overflow用户
提问于 2014-10-08 13:03:37
回答 1查看 1.4K关注 0票数 0

我的整个应用程序是在肖像模式,我在我的应用程序播放youtube视频。对于你来说,我用的是UIWebview。当用户单击UIWebview中的play按钮时,它会自动启动MPMoviePlayerController。因此,我没有声明任何MPMoviePlayerController对象。所以我希望MPMoviePlayerController同时支持人像和景观定位。所以请建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-08 13:26:02

如果使用NavigationController,则可以将其子类并执行以下操作:

代码语言:javascript
复制
#import "MainNavigationController.h"
#import <MediaPlayer/MediaPlayer.h>

@implementation MainNavigationController

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    if ([[[self.viewControllers lastObject] presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
    {
        return UIInterfaceOrientationMaskAll;
    }
    else
    {
        return UIInterfaceOrientationMaskPortrait;
    }

}
@end

然后,你应该设置你的应用程序来支持所有的方向,只有当它在播放你的电影“MPMoviePlayerController`”时,这段代码才允许方向改变。

当调用您的movie时,您应该发送一个通知,因此如果用户在portrait以外的任何方向关闭它,它将切换回portrait

就像这样:

代码语言:javascript
复制
- (IBAction)playButton:(id)sender {

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlaybackDidFinish)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:self.player.moviePlayer];

    NSURL *url = [NSURL URLWithString:videoUrl];

    self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

    [self presentMoviePlayerViewControllerAnimated:self.player]; 
}

-(void)moviePlaybackDidFinish
{
    [[UIDevice currentDevice] setValue:
     [NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
                                forKey:@"orientation"];
}

这应该是为了你,让我知道是怎么回事。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26257615

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档