Objective-C iOS MPMoviePlayerController不播放电影不返回

Objective-C iOS MPMoviePlayerController不播放电影不返回,ios,iphone,objective-c,ipad,mpmovieplayercontroller,Ios,Iphone,Objective C,Ipad,Mpmovieplayercontroller,这是必须在电视中播放的电影,如果它存在,如果没有,这必须在内部屏幕中播放电影。 但当我设置player background player.view.backgroundColor=[UIColor blueColor]时,它不会播放只显示蓝色屏幕的电影 若我在emulator中设置tvout硬件,则tvout上会显示播放器蓝屏,并在控制台中返回消息: 2013-12-17 23:57:59.576预计将有RAT[8609:70b]应用程序窗口 在应用程序启动结束时使用根视图控制器 代码是: /

这是必须在电视中播放的电影,如果它存在,如果没有,这必须在内部屏幕中播放电影。 但当我设置player background player.view.backgroundColor=[UIColor blueColor]时,它不会播放只显示蓝色屏幕的电影

若我在emulator中设置tvout硬件,则tvout上会显示播放器蓝屏,并在控制台中返回消息:

2013-12-17 23:57:59.576预计将有RAT[8609:70b]应用程序窗口 在应用程序启动结束时使用根视图控制器

代码是:

//
//  ViewController.m
//  RAT
//
//  Created by Dmitriy Pushkarev on 28/11/13.
//  Copyright (c) 2013 ЯB RoyalBlue. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end



@implementation ViewController


MPMoviePlayerController *player;
UIWindow *newwindow;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.



    player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"]];




    [player prepareToPlay];
    [player play];
    [player.view setFrame:self.view.bounds];

    player.view.backgroundColor = [UIColor blueColor];
    player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    CGSize maxSize;




    if([[UIScreen screens]count] > 1) {
        NSLog(@"external screen");
        newwindow = [[UIWindow alloc] init];
        // There is a external display.
        UIScreenMode *maxScreenMode;
        for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
        {
            UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
            if(current.size.width > maxSize.width)
            {
                maxSize = current.size;
                maxScreenMode = current;
            }
        }
        UIScreen *external = [[UIScreen screens] objectAtIndex:1];
        external.currentMode = maxScreenMode;
        newwindow.screen = external;
        // setting external display size.
        CGPoint point = CGPointMake(0.0f, 0.0f);
        // CGSize size = CGSizeMake(1024.0f, 768.0f);
        CGSize size = maxSize;
        CGRect frame = player.view.frame;
        frame.origin = point;
        frame.size.width = size.width;
        frame.size.height = size.height;
        [player.view setFrame:frame];
        [player setControlStyle:MPMovieControlModeHidden];
        [player prepareToPlay];
        [player play];
        [newwindow addSubview:player.view];
        [newwindow makeKeyAndVisible];

    } else {

        [self.view addSubview:player.view];
        [player.view becomeFirstResponder];

        NSLog(@"Display not connected");
    }


    ///////////////////////////////
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
//
//ViewController.m
//老鼠
//
//由德米特里·普什卡雷夫于2013年11月28日创作。
//版权所有(c)2013ЯB RoyalBlue。版权所有。
//
#导入“ViewController.h”
@界面视图控制器()
@结束
@实现视图控制器
MPMoviePlayerController*播放器;
UIWindow*新窗口;
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
player=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:@”http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"]];
[玩家准备玩];
[玩家游戏];
[player.view setFrame:self.view.bounds];
player.view.backgroundColor=[UIColor blueColor];
player.view.autoresizingMask=uiviewsautoresizingflexiblewidth | uiviewsautoresizingflexiblewhight;
CGSize-maxSize;
如果([[UIScreen screens]计数]>1){
NSLog(“外部屏幕”);
newwindow=[[UIWindow alloc]init];
//有一个外部显示器。
UIScreenMode*maxScreenMode;
对于(int i=0;i<[[UIScreen screens]objectAtIndex:1]availableModes]count];i++)
{
UIScreenMode*current=[[[UIScreen screens]对象索引:1]可用模板]对象索引:i];
if(current.size.width>maxSize.width)
{
maxSize=当前的.size;
maxScreenMode=电流;
}
}
UIScreen*外部=[[UIScreen screens]对象索引:1];
external.currentMode=maxScreenMode;
newwindow.screen=外部;
//设置外部显示大小。
CGPoint=CGPointMake(0.0f,0.0f);
//CGSize=CGSizeMake(1024.0f,768.0f);
CGSize=最大尺寸;
CGRect frame=player.view.frame;
frame.origin=点;
frame.size.width=size.width;
frame.size.height=size.height;
[player.view setFrame:frame];
[player setControlStyle:MPMovieControlModeHidden];
[玩家准备玩];
[玩家游戏];
[newwindowaddsubview:player.view];
[newwindow makeKeyAndVisible];
}否则{
[self.view addSubview:player.view];
[player.view成为第一响应者];
NSLog(@“显示器未连接”);
}
///////////////////////////////
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
@结束
进展。。。 好啊我更新了代码,现在它只能在内部显示上工作。 在TVout上,我只看到蓝色屏幕,听视频中的声音,但什么也看不到,只有蓝色屏幕

和控制台消息-应用程序窗口应在应用程序启动结束时具有根视图控制器

更大的进步。。
一切正常!但我在日志中得到消息:应用程序窗口在应用程序启动结束时应该有一个根视图控制器

我不知道这是否是您唯一的问题,但您的播放器将在viewDidLoad退出后被释放,因为您将它创建为一个局部变量。为它创建一个强属性,它应该可以工作。

将您的播放器创建为属性:

@property (strong, nonatomic) MPMoviePlayerViewController *streamPlayer;
在viewDidLoad中播放视频:

NSURL *streamURL = [NSURL URLWithString:@"http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8"];
_streamPlayer = [[CSJMovieViewController alloc] initWithContentURL:streamURL];
[_streamPlayer.view setFrame:self.view.bounds];
[self.view addSubview:_streamPlayer.view];
[_streamPlayer.moviePlayer play];
我不确定您为什么要创建自己的
UIWindow
对象。播放视频时不需要这样做。您只需将播放器添加到
UIViewController
的视图中即可。我怀疑您收到的错误消息可能是创建该窗口的结果

问题可能是:

[newwindow addSubview:player.view];

从我在代码中看到的情况来看,在
ui窗口上没有
UIViewController
设置为
rootViewController
,应该有。

确定。我解决了在电视上看电影的问题,但控制台中的消息仍在登录-应用程序窗口预计在应用程序启动结束时会有一个根视图控制器


我需要做什么?

谢谢。但我现在还有其他麻烦。