问题描述
根据Apple的MPMoviePlayerController doc:
According to Apple's MPMoviePlayerController doc:
MPMoviePlayerPlaybackDidFinishNotification -
如果电影播放器以全屏模式显示且用户点击,则不会发送此通知完成按钮。
MPMoviePlayerPlaybackDidFinishNotification -This notification is not sent in cases where the movie player is displaying in fullscreen mode and the user taps the Done button.
对我来说这是错误的。使用下面的代码,当我点击完成按钮时,会调用playerPlaybackDidFinish。
Seems to me this is dead wrong. Using the code below, playerPlaybackDidFinish gets called when I tap the done button.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player];
- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
NSLog(@"WHY?");
self.player.fullscreen = NO;
}
我需要区分用户点击完成按钮和电影完成全部通过回放的方式。当电影结束时,playerPlaybackDidFinish会被调用,但就像我说的那样,当你点击Done时它也被调用。
I need to distinguish between the user tapping the done button and the movie finishing all the way through playback. playerPlaybackDidFinish does get called when the movie ends, but like I said it also gets called when you tap Done.
推荐答案
这是怎么回事检查MPMoviePlayerPlaybackDidFinishReasonUserInfoKey,它是MPMoviePlayerPlaybackDidFinishNotification通知的一部分
Here is how you check the MPMoviePlayerPlaybackDidFinishReasonUserInfoKey which is part of the notification of MPMoviePlayerPlaybackDidFinishNotification
- (void) playbackDidFinish:(NSNotification*)notification {
int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackEnded) {
//movie finished playin
}else if (reason == MPMovieFinishReasonUserExited) {
//user hit the done button
}else if (reason == MPMovieFinishReasonPlaybackError) {
//error
}
}
这篇关于不应该调用MPMoviePlayerPlaybackDidFinishNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!