0

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

我正在使用 MPMoviePlayerController 播放视频。我已经按照 这个教程。但是,我仍然无法在模拟器中播放视频。

这是我的代码:

- (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)
4

2 回答 2

3

我终于完成了这项工作。iOS 5.0 之后,MPMoviePlayerController需要声明为属性。因此,我将其添加为属性并且它起作用了。

于 2012-12-19T15:10:10.120 回答
0

你能试试这个代码:

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

代替 :

[self.view addSubview:moviePlayerController.view];

希望这会有所帮助。干杯。

于 2012-12-19T14:49:45.550 回答