0

MPMoviePlayerControllerゲーム開始前にm4vファイルを再生するために使用しようとしています。ゲームがcocos2dベース。

必要なファイルでを作成しMPMoviePlayerController、子としてCCDirector( のサブクラスであるUIViewController) に追加しました。子として追加する理由MPMoviePlayerControllerは、ゲームをバックグラウンドでロードし続けたいからです。

私の問題はMPMoviePlayerController、ビデオの終了後に を削除する方法が見つからないことです。

提案をお願いします。

前もって感謝します。

4

2 に答える 2

0

MPMoviePlayerPlaybackDidFinishNotification通知をリッスンしてから、サブビューを削除できるはずです。このコードは私のテストで機能しました:

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
self.player = moviePlayer;

moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
[moviePlayer prepareToPlay];

moviePlayer.view.frame = self.view.bounds;
moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:moviePlayer.view];

[moviePlayer play];

// wait for the video to finish...
MyViewController __weak *weakSelf = self;
[[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerPlaybackDidFinishNotification object:self.player queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
  [[NSNotificationCenter defaultCenter] removeObserver:weakSelf name:MPMoviePlayerPlaybackDidFinishNotification object:weakSelf.player];

  // remove the view
  [weakSelf.player.view removeFromSuperview];
}];

それでも問題が解決しない場合は、プレーヤーの作成とセットアップのコードを投稿して、何が起こっているのかを把握できるようにする必要があります。

于 2012-07-22T03:38:02.400 に答える
0

cocos2D ゲームでは、CCVideoPlayer クラスが最適で、動画を簡単に再生できます。延長はこちら

于 2012-07-20T18:39:50.457 に答える