我想在全屏模式下显示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 以来可能有变化?