未播放ios应用程序的视频

未播放ios应用程序的视频,ios,Ios,我试图在点击UITabBar项目时播放视频。我遵循了本教程: 每当我单击UITabBar项时,它只显示普通视图,而不添加电影视图。这是我的密码: - (void)viewDidLoad { NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video" ofType:@"m4v"]]; MPMoviePlayerCont

我试图在点击UITabBar项目时播放视频。我遵循了本教程:

每当我单击UITabBar项时,它只显示普通视图,而不添加电影视图。这是我的密码:

- (void)viewDidLoad {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"video" ofType:@"m4v"]];
MPMoviePlayerController *moviePlayer =  [[MPMoviePlayerController alloc]
                initWithContentURL:url];

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

moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
我还发现以下错误:

2013-01-26 15:21:08.243 Smart Mower[61339:c07] [MPAVController] Autoplay: Disabling        autoplay for pause
2013-01-26 15:21:08.244 Smart Mower[61339:c07] [MPAVController] Autoplay: Disabling autoplay
2013-01-26 15:21:08.260 Smart Mower[61339:c07] [MPAVController] Autoplay: Skipping   autoplay, disabled (for current item: 1, on player: 0)
有人能帮我吗?
谢谢

您好,请尝试添加以下内容

1) 确保在运行时将电影添加到“生成阶段”下的复制包资源中

2) 尝试将代码添加到声明中,如下所示:

            NSString *path = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4"];
            NSURL *url = [NSURL fileURLWithPath:path];
            moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
            moviePlayer.view.frame = self.view.frame;
            moviePlayer.moviePlayer.shouldAutoplay=YES;
            moviePlayer.moviePlayer.controlStyle = MPMovieControlStyleNone;
           [moviePlayer.moviePlayer setFullscreen:YES animated:YES];
           [self.view addSubview:moviePlayer.view];
           [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieFinishedCallback:)
                                           name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayer.moviePlayer];

            [moviePlayer.moviePlayer play];

让我知道你是如何表现出来的。

你是如何表现出来的?我确保视频正在添加。用上面的代码替换了我的代码,这些是我单击UITabBar时遇到的错误。我得到了与原始帖子相同的错误,然后我得到了关于CGContext的错误<代码>无效的上下文0x0是,我做了。不过,我用另一种方法解决了这个问题。谢谢你的帮助!