MPMoviePlayerPlaybackDidFinishNotification 在不应调用时被调用
根据苹果的 MPMoviePlayerController 文档:
MPMoviePlayerPlaybackDidFinishNotification - 如果电影播放器以全屏模式显示并且用户点击“完成”按钮,则不会发送此通知。
在我看来这是完全错误的。使用下面的代码,当我点击完成按钮时,playerPlaybackDidFinish 就会被调用。
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.player];
- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
NSLog(@"WHY?");
self.player.fullscreen = NO;
}
我需要区分用户点击“完成”按钮和电影在播放过程中完成的情况。当电影结束时,playerPlaybackDidFinish 确实会被调用,但就像我说的,当你点击“完成”时它也会被调用。
According to Apple's MPMoviePlayerController doc:
MPMoviePlayerPlaybackDidFinishNotification -
This notification is not sent in cases where the movie player is displaying in fullscreen mode and the user taps the Done button.
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;
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下是检查 MPMoviePlayerPlaybackDidFinishReasonUserInfoKey 的方法,它是 MPMoviePlayerPlaybackDidFinishNotification 通知的一部分
Here is how you check the MPMoviePlayerPlaybackDidFinishReasonUserInfoKey which is part of the notification of MPMoviePlayerPlaybackDidFinishNotification
当电影一直播放到最后时,我使用以下方法执行某些操作:
I am using the following to do something when a movie is played all the way to the end:
当您收到通知时,您可以检查播放器的 endPlaybackTime。如果是-1,那么电影就自然结束了。
对于流媒体内容,您可以检查 MPMoviePlayerPlaybackDidFinishNotification 上 userInfo 内的 MPMoviePlayerPlaybackDidFinishReasonUserInfoKey。
如果它等于 MPMovieFinishReasonUserExited 则表示用户停止播放内容。
When you get the notification you can check the player's endPlaybackTime. If it's -1 then the movie finished all the way back naturally.
For streamed content, you can check the MPMoviePlayerPlaybackDidFinishReasonUserInfoKey inside the userInfo on the MPMoviePlayerPlaybackDidFinishNotification.
If it's equal to MPMovieFinishReasonUserExited then it's the user stopped playing the content.
确保为
Make sure for