Ios MPMoviePlayerController赢得';使用故事板/显示黑屏时不播放

Ios MPMoviePlayerController赢得';使用故事板/显示黑屏时不播放,ios,objective-c,mpmovieplayercontroller,Ios,Objective C,Mpmovieplayercontroller,我试图在我的应用程序中在后台播放一段视频,但在我使用故事板时它不起作用。我读了一些关于ARC的东西,尝试了所有的方法,但我的视频不会简单地播放。我尝试了完全相同的方法,但在另一个项目中,我删除了故事板文件,并且成功了。我需要在我使用故事板的项目中使用它。请帮帮我 代码如下: ViewController.m: #import "AnimatedLoginViewController.h" #import <AVFoundation/AVFoundation.h> #import &l

我试图在我的应用程序中在后台播放一段视频,但在我使用故事板时它不起作用。我读了一些关于ARC的东西,尝试了所有的方法,但我的视频不会简单地播放。我尝试了完全相同的方法,但在另一个项目中,我删除了故事板文件,并且成功了。我需要在我使用故事板的项目中使用它。请帮帮我

代码如下:

ViewController.m:

#import "AnimatedLoginViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import <QuartzCore/QuartzCore.h>

@interface ViewController (){
    MPMoviePlayerController *player;
}

@property (nonatomic, strong) MPMoviePlayerController *player;

@end

@implementation ViewController

@synthesize player;

- (void)viewDidLoad
{
    [super viewDidLoad];

    CGRect screen = [[UIScreen mainScreen] bounds];

    NSURL *movieUrl = [[NSBundle mainBundle] URLForResource:@"background"  withExtension:@"mp4"];

    self.player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];

    player.view.frame = screen;
    player.scalingMode = MPMovieScalingModeFill;
    [self.player setControlStyle:MPMovieControlStyleNone];
    [self.view addSubview:player.view];
    [player prepareToPlay];


    UIImageView *logo = [[UIImageView alloc] initWithFrame:CGRectMake(65, 90, 190, 40)];
    logo.backgroundColor = [UIColor clearColor];
    [logo setImage:[UIImage imageNamed:@"logo_welcome.png"]];

    [self.view addSubview:logo];


    UIFont *boldFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:16.0];
    UIFont *defaultFont = [UIFont fontWithName:@"HelveticaNeue" size:16.0];


    NSDictionary * attributes = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[UIColor whiteColor], defaultFont, nil] forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName, NSFontAttributeName, nil]];

    NSDictionary * attributesBold = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[UIColor whiteColor], boldFont, nil] forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName, NSFontAttributeName, nil]];

    attributes = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[UIColor blackColor], defaultFont, nil] forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName, NSFontAttributeName, nil]];

    attributesBold = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[UIColor blackColor], boldFont, nil] forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName, NSFontAttributeName, nil]];

    UIButton *emailButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [emailButton setFrame:CGRectMake(10, screen.size.height==568?455:370, 300, 43)];

    attributedString = [[NSMutableAttributedString alloc] init];
    [attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Enter your work " attributes:attributes]];

    [attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Email" attributes:attributesBold]];
    [emailButton setAttributedTitle:attributedString forState:UIControlStateNormal];

    [emailButton setBackgroundImage:[UIImage imageNamed:@"SignInMailButton.png"] forState:UIControlStateNormal];
    [emailButton setBackgroundImage:[UIImage imageNamed:@"SignInMailButtonTap.png"] forState:UIControlStateHighlighted];
    [emailButton setBackgroundImage:[UIImage imageNamed:@"SignInMailButtonTap.png"] forState:UIControlStateSelected];
    [emailButton setEnabled:YES];
    [self.view addSubview:emailButton];


    boldFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:14.0];
    defaultFont = [UIFont fontWithName:@"HelveticaNeue" size:14.0];

    attributes = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[UIColor grayColor], defaultFont, nil] forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName, NSFontAttributeName, nil]];

    attributesBold = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[UIColor whiteColor], boldFont, nil] forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName, NSFontAttributeName, nil]];

    UIButton *signInButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [signInButton setFrame:CGRectMake(10, screen.size.height==568?500:410, 300, 43)];

    attributedString = [[NSMutableAttributedString alloc] init];
    [attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Do you have an activation code? " attributes:attributes]];

    [attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:@"Enter now" attributes:attributesBold]];
    [signInButton setAttributedTitle:attributedString forState:UIControlStateNormal];
    [signInButton setEnabled:YES];
    [self.view addSubview:signInButton];


    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playVideo)
                                                 name:MPMoviePlayerReadyForDisplayDidChangeNotification
                                               object:player];

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

    [player play];
}

- (void)moviePlayerDidFinish:(NSNotification *)note
{
    if (note.object == self.player) {
        NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
        if (reason == MPMovieFinishReasonPlaybackEnded)
        {
            [self.player play];
        }
    }
}

-(void)playVideo{
    [player play];
}

@end
#导入“AnimatedLoginViewController.h”
#进口
#进口
#进口
@界面视图控制器(){
MPMoviePlayerController*播放器;
}
@属性(非原子,强)MPMoviePlayerController*播放器;
@结束
@实现视图控制器
@综合玩家;
-(无效)viewDidLoad
{
[超级视图下载];
CGRect屏幕=[[UIScreen mainScreen]边界];
NSURL*movieUrl=[[NSBundle mainBundle]URLForResource:@“background”带扩展名:@“mp4”];
self.player=[[MPMoviePlayerController alloc]initWithContentURL:movieUrl];
player.view.frame=屏幕;
player.scalingMode=MPMovieScalingModeFill;
[self.player setControlStyle:MPMovieControlStyleNone];
[self.view addSubview:player.view];
[玩家准备玩];
UIImageView*徽标=[[UIImageView alloc]initWithFrame:CGRectMake(65,90,190,40)];
logo.backgroundColor=[UIColor clearColor];
[logo setImage:[UIImage ImageName:@“logo_welcome.png”];
[self.view addSubview:logo];
UIFont*boldFont=[UIFont fontWithName:@“HelveticaNeue粗体”大小:16.0];
UIFont*defaultFont=[UIFont fontWithName:@“HelveticaNeue”大小:16.0];
NSDictionary*attributes=[NSDictionary Dictionary WithObjects:[NSArray arrayWithObjects:[UIColor whiteColor],defaultFont,nil]forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName,NSFontAttributeName,nil];
NSDictionary*attributesBold=[NSDictionary Dictionary Dictionary WithObjects:[NSArray arrayWithObjects:[UIColor whiteColor],boldFont,nil]forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName,NSFontAttributeName,nil];
attributes=[NSDictionary Dictionary Dictionary WithObjects:[NSArray arrayWithObjects:[UIColor blackColor],defaultFont,nil]forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName,NSFontAttributeName,nil]];
attributesBold=[NSDictionary Dictionary Dictionary WithObjects:[NSArray arrayWithObjects:[UIColor blackColor],boldFont,nil]forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName,NSFontAttributeName,nil];
UIButton*emailButton=[UIButton按钮类型:UIButtonTypeCustom];
[emailButton setFrame:CGRectMake(10,屏幕大小高度==568?455:370300,43)];
attributedString=[[NSMutableAttributedString alloc]init];
[AttributeString AppendedAttributeString:[[NSAttributeString alloc]initWithString:@“输入您的工作”属性:属性]];
[AttributeString AppendedAttributeString:[[NSAttributeString alloc]initWithString:@“电子邮件”属性:AttributeBold]];
[emailButton setAttributedTitle:attributedString for状态:UIControlStateNormal];
[emailButton setBackgroundImage:[UIImage ImageName:@“SignInMailButton.png”]用于状态:UIControlStateNormal];
[emailButton setBackgroundImage:[UIImage ImageName:@“SignInMailButtonTap.png”]用于状态:UIControlStateHighlighted];
[emailButton setBackgroundImage:[UIImage ImageName:@“SignInMailButtonTap.png”]用于状态:UIControlStateSelected];
[emailButton设置已启用:是];
[self.view addSubview:emailButton];
boldFont=[UIFont fontWithName:@“HelveticaNeue Bold”大小:14.0];
defaultFont=[UIFont fontWithName:@“HelveticaNeue”大小:14.0];
attributes=[NSDictionary Dictionary WithObjects:[NSArray arrayWithObjects:[UIColor grayColor],defaultFont,nil]forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName,NSFontAttributeName,nil]];
attributesBold=[NSDictionary Dictionary Dictionary WithObjects:[NSArray arrayWithObjects:[UIColor whiteColor],boldFont,nil]forKeys:[NSArray arrayWithObjects:NSForegroundColorAttributeName,NSFontAttributeName,nil];
UIButton*signInButton=[UIButton按钮类型:UIButtonTypeCustom];
[SigninButtonSetFrame:CGRectMake(10,屏幕大小高度==568?500:410300,43)];
attributedString=[[NSMutableAttributedString alloc]init];
[attributedString appendAttributedString:[[NSAttributedString alloc]initWithString:@“您有激活码吗?”属性:属性]];
[AttributeString AppendedAttributeString:[[NSAttributeString alloc]initWithString:@“立即输入”属性:AttributeBold]];
[登录按钮setAttributedTitle:attributedString for状态:UIControlStateNormal];
[登录按钮设置启用:是];
[self.view addSubview:登录按钮];
[[NSNotificationCenter defaultCenter]添加观察者:self
选择器:@selector(播放视频)
名称:MPMoviePlayerReadyFordDisplayDidChangeNotification
对象:玩家];
[[NSNotificationCenter defaultCenter]添加观察者:self
选择器:@selector(moviePlayerDidFinish:)
名称:MPMoviePlayerPlaybackDidFinishNotification
对象:self.player];
[玩家游戏];
}
-(无效)影剧演员设计:(NSNotification*)注释
{
if(note.object==self.player){
NSInteger原因=[[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey]integerValue];
如果(原因==MPMovieFinishRasonPlayBackend)
{
[self.player play];
}
}
}
-(无效)播放视频{
[玩家游戏];
}
@结束

故事板中有哪些控制器?你看到电影播放器了吗,但它不播放?我没有使用任何控制器。我正在使用这个库,请查看:对不起,我说的是视图控制器。显而易见