MPMoviePlayer控制器不播放视频

时间:2012-12-19 14:42:44

标签: iphone ios ios6 mpmovieplayercontroller

我正在开发一款需要使用Xcode 4.5.2和iOS 6.0播放视频的应用。

我正在使用MPMoviePlayerController播放视频。我跟着this tutorial。但是,我仍然无法在模拟器中播放视频。

这是我的代码:

- (IBAction)playVideo:(id)sender {
 NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"Movie-1" ofType:@"mp4"];
 NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
 MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
 moviePlayerController.shouldAutoplay =YES ;
 moviePlayerController.controlStyle = MPMovieControlStyleDefault ;
 moviePlayerController.scalingMode = MPMovieScalingModeFill ;
 [moviePlayerController.view setFrame:CGRectMake(0, 0, 360, 200)];
 [self.view addSubview:moviePlayerController.view];
 [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(moviePlaybackComplete:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayerController];
[moviePlayerController play ] ;

}

- (void)moviePlaybackComplete:(NSNotification *)notification
{
    MPMoviePlayerController *moviePlayerController = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:moviePlayerController];

    [moviePlayerController.view removeFromSuperview];
}

我已经看了很多SO问题,但没有一个能解决我的问题。我还尝试创建 containerView 并将我的MPMoviePlayerController添加到我的 containerView 中。我没有成功。

我也试过MPMoviePlayerViewController,到目前为止我能够让它发挥作用。它的另一个问题是,我不能setFrameMPMoviePlayerViewController。但是,我想将setFrame设置为我的视频播放器。它的大小不可能是全屏的。因为,我需要在我的视频播放器下面显示一些按钮。

你们有什么想法我能做到这一点吗?

编辑:控制台输出

2012-12-19 16:29:21.554 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:21.555 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:21.565 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:27.230 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:27.231 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:27.241 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:27.706 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:27.707 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:27.718 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:27.919 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:27.920 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:27.930 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:28.077 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:28.077 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:28.088 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:28.219 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:28.220 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:28.230 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:28.368 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:28.368 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:28.382 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:28.511 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:28.512 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:28.521 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-12-19 16:29:28.692 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-12-19 16:29:28.692 Coverzzz[4952:c07] [MPAVController] Autoplay: Disabling autoplay
2012-12-19 16:29:28.702 Coverzzz[4952:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)

2 个答案:

答案 0 :(得分:3)

我终于完成了这项工作。在iOS 5.0之后,需要将MPMoviePlayerController声明为属性。所以,我添加它作为一个属性,它的工作原理。

答案 1 :(得分:0)

你可以尝试这段代码:

MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:_urlToLoad];
[self presentModalViewController:mp animated:YES];

而不是:

[self.view addSubview:moviePlayerController.view];

希望这会有所帮助。欢呼声。