MPMoviePlayerViewControllerをフル スクリーン モードで表示したいのですが、movieplayercontroller ビューのフルスクリーン ボタンが押されたときに、予想どおり、最初にMPMoviePlayerWillEnterFullscreenNotificationが呼び出されますが、MPMoviePlayerPlaybackDidFinishNotificationも送信されます。理由としてMPMovieFinishReasonPlaybackEndedと表示されていますが、何が間違っているのかわかりません。(さらに、私はiOS 6.0とXCode 4.5.1を使用します)
私の期待は、MPMoviePlayerWillEnterFullscreenNotificationだけが呼び出されているということです。
以下のコードの簡単な説明: MovieplayerViewController のビューは、コンテンツ ビューの小さなサブビューに表示されています。フルスクリーン ボタンをタップすると、最初にフルスクリーンとして表示されますが、終了ボタンも呼び出されて再生が停止します (クラッシュは発生しません)。
MPMoviePlayerViewController *playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[playerViewController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
[playerViewController.moviePlayer setScalingMode:MPMovieScalingModeFill];
CGRect rect = videoView.frame;
rect.origin = CGPointZero;
[playerViewController.view setFrame:rect];
[playerViewController.moviePlayer prepareToPlay];
//movie this is my contents subview, where i add the viewcontroller's view as a subbview
[self.videoView addSubview:playerViewController.view];
[self.videoView setHidden:NO];
playerViewController.moviePlayer.useApplicationAudioSession = NO;
[playerViewController.moviePlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerDidFinishNotification:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerWillEnterFullscreenNotification:)
name:MPMoviePlayerWillEnterFullscreenNotification
object:playerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerWillExitFullscreenNotification:)
name:MPMoviePlayerWillExitFullscreenNotification
object:playerViewController.moviePlayer];
//i store the movieplayer in a property, so i can use it for further operations
self.myPlayer = playerViewController;
[playerViewController release];
以上です!
サイズ変更 (またはフルスクリーン) ボタンが押されると、moviePlayerDidFinishNotification: メソッドも呼び出されます。
- (void)moviePlayerDidFinishNotification:(NSNotification*) aNotification {
int reason = [[[aNotification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackEnded) {
//movie finished playin
//in debug mode, it stops right at the NSLog
NSLog(@"");
}
else if (reason == MPMovieFinishReasonUserExited) {
//user hit the done button
}
else if (reason == MPMovieFinishReasonPlaybackError) {
//error
}
.. }
何か間違っているのでしょうか、それとも iOS 6.0 から変更されたのでしょうか?