7

モーダルに表示される MPMoviePlayerViewController は、presentMoviePlayerViewControllerAnimated:コンテンツの再生が終了すると自動的に閉じます。

後で他のコンテンツを再生したいので、これを無効にしようとしました。ただし、NSNotificationCenter に登録して[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer];他のコンテンツを設定しても、無視されます。

MPMoviePlayerViewController が自動的に閉じないようにするにはどうすればよいですか?

アップデート:

明確にするために、この質問は自動非表示の削除に関するものであり、無効になっている「完了」ボタンの処理に関するものではありません。選択した回答が反映されます。開発者が MPMoviePlayerViewController を閉じる独自の手段を追加することを想定しているため、これは仕様によるものです。ただし、@bicksterの回答は「完了」ボタンも扱っています。

4

4 に答える 4

20

このコードを使用して、viewcontroller が自動的に閉じるのを停止し、ユーザーが [Done] ボタンをクリックしたときにイベントをキャプチャして、自分で viewcontroller を閉じることができます。

ステップ 1. - MPMoviePlayerViewController を割り当てる

videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[[NSURL alloc ]initWithString:[aURL];

ステップ 2. - デフォルトの MPMoviePlayerPlaybackDidFinishNotification オブザーバーを削除し、独自のオブザーバーを追加する

[[NSNotificationCenter defaultCenter] removeObserver:videoPlayer
name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(videoFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayer.moviePlayer];

ステップ 3. - ビューコントローラーを提示する

[self presentMoviePlayerViewControllerAnimated:videoPlayer];

ステップ 4. - videoFinish: メソッドを追加する

-(void)videoFinished:(NSNotification*)aNotification{
    int value = [[aNotification.userInfo valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
    if (value == MPMovieFinishReasonUserExited) {
        [self dismissMoviePlayerViewControllerAnimated];
    }
}
于 2013-10-25T18:02:11.593 に答える
20

このブログ記事のおかげで、MPMoviePlayerViewController は作成時に NSNotificationCenter に自動的に登録されることがわかりました。最初にこの登録を削除する必要があります。そうすれば、自動的に削除されなくなります。

// Initialize the movie player view controller with a video URL string
MPMoviePlayerViewController *playerVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:aVideoUrl]] autorelease];
// Remove the movie player view controller from the "playback did finish" notification observers
[[NSNotificationCenter defaultCenter] removeObserver:playerVC  name:MPMoviePlayerPlaybackDidFinishNotification object:playerVC.moviePlayer];
于 2012-11-16T16:30:15.550 に答える
2

このようなものを試すことができます。

mpmovieplayercontroller がビデオの再生を終了し、メソッドmovieFinishedCallback: implemectで通知を受け取ったとき

       [playerVC.movieplayer setContentURL:// set the url of the file you want to play here];

       [playerVC.moviePlayer play];

お役に立てれば

于 2012-11-16T17:25:09.390 に答える
0

MPMoviePlayerPlaybackDidFinishNotificationから外したら「完了」ボタンが効かなくなったのでNSNotificationCenter、リピートモードを に変更MPMovieRepeatModeOne。その後、ビデオが繰り返されることを除いて、すべてが正常に機能しています。

MPMoviePlayerViewController *playerVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:aVideoUrl]] autorelease];
[playerVC.moviePlayer setRepeatMode:MPMovieRepeatModeOne];
于 2014-03-31T09:35:24.263 に答える