【问题标题】:How do I make my MPMoviePlayerController Play in Landscape?如何让我的 MPMoviePlayerController 横向播放?
【发布时间】:2012-09-22 16:30:36
【问题描述】:

我正在尝试让我的 youtube 视频以横向模式播放。我关闭了左右横向以支持设备方向,因为如果它打开,每个视图都可以横向。我正在为 iOS 6 构建这个。如何让我的视频横向播放。

这是我的代码

#import "VideoTViewController.h"
#import "HCYoutubeParser.h"
#import <MediaPlayer/MediaPlayer.h>

@interface VideoTViewController ()

@end

@implementation VideoTViewController
@synthesize tLabel;

-(IBAction)playVideo
{

    NSDictionary *videos = [HCYoutubeParser h264videosWithYoutubeURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=zz_bJ58LfCg&feature=youtu.be"]];

    MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[videos objectForKey:@"medium"]]];

    [self presentViewController:mp animated:YES completion:nil];
}

编辑:

我做了以下事情:

创建了一个新课程

AboutNavViewController(它是 UiNavigationController 的子类)

#import "AboutNavViewController.h"

@interface AboutNavViewController ()

@end

@implementation AboutNavViewController


- (BOOL)shouldAutorotate {
    return NO;
}

- (BOOL)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
@end

在我的 aboutviewcontroller(它是 uiviewcontroller 的子类)中

#import "AboutViewController.h"
#import "AboutNavViewController.h"

@interface AboutViewController ()

@end

@implementation AboutViewController
@synthesize aLabel;

- (void)viewDidLoad
{
    [super viewDidLoad];

    CGRect frame = CGRectMake(0, 0, 320, 44);
    aLabel = [[UILabel alloc] initWithFrame:frame];
    aLabel.backgroundColor = [UIColor clearColor];
    [aLabel setFont:[UIFont fontWithName:@"SerifGothic LT Black" size:25]];
    aLabel.text = @"Sephardi Jews";
    aLabel.textAlignment = NSTextAlignmentCenter;
    aLabel.textColor =[UIColor whiteColor];
    self.navigationItem.titleView = aLabel;

    AboutNavViewController *about = [[AboutNavViewController alloc] init];

    [self presentViewController:about animated:YES completion:nil];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

@end

我收到以下错误:

开始/结束外观转换的不平衡调用。

我做错了什么?

【问题讨论】:

    标签: objective-c xcode mpmovieplayercontroller ios6


    【解决方案1】:

    注意:您必须将横向左右添加到 Info.plist 中支持的界面方向才能正常工作。

    系统通过将应用程序的supportedInterfaceOrientationsForWindow: 方法返回的值与最顶层全屏控制器的supportedInterfaceOrientations 方法返回的值相交来确定是否支持方向。

    从上一个答案中添加了 iOS 6 自动旋转方法”

    @interface MyMovieViewController : MPMoviePlayerViewController
    @end
    
    @implementation MyMovieViewController
    
    - (BOOL)shouldAutorotate 
    {
        return YES;
    }
    
    - (NSInteger)supportedInterfaceOrientations 
    {
        return UIInterfaceOrientationMaskLandscape;
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
    }
    
    @end
    

    【讨论】:

    • 很好用。现在,如果我想要一个由导航控制器控制的视图只能在纵向模式下工作,该怎么办
    • 同样的事情。子类化导航控制器并仅在自动旋转方法上返回肖像。请记住在 Info.plist 中将纵向模式添加到支持的界面方向
    • 我编辑了我的问题,向你展示我做了什么,以及我得到的错误。这真的很奇怪。它显示一个黑屏,而不是向我显示带有我创建的关于想法的 uitextview。
    • 我认为您不应该在 viewDidLoad 方法中调用 presentViewController,因为视图堆栈可能尚未完全创建。尝试将其放入您的 viewDidAppear 或 viewWillAppear 方法并使用 performSelector:withDelay (几秒钟应该没问题)。
    • performSelector怎么做,能给我举个例子吗?
    猜你喜欢
    • 1970-01-01
    • 2012-03-16
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多