0

单击 UITabBar 项目时,我正在尝试播放视频。我遵循了本教程:http ://www.techotopia.com/index.php/Video_Playback_from_within_an_iOS_5_iPhone_Application

每当我单击 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)

有人可以帮我吗?谢谢!

4

1 回答 1

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];

让我知道你是怎么出来的。

于 2013-01-26T20:22:20.733 回答