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を作成して、自分のcontainerViewに追加しようとしました。私はそれを機能させませんでした。MPMoviePlayerController

私も試してみましたがMPMoviePlayerViewController、これまでのところ機能させることができます。それに関する別の問題、私はできませsetFrameMPMoviePlayerViewController。しかし、私は自分のビデオ プレーヤーに Frame を設定したいと考えています。そのサイズをフルスクリーンにすることはできません。ビデオプレーヤーの下にいくつかのボタンを表示する必要があるためです。

どうすればそれを達成できますか?

編集:コンソール出力

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 に答える