Iphone MPMoviePlayerPlaybackDidFinishNotification出现问题
我有一个奇怪的问题。播放结束后,我需要停止播放机。我正在使用Iphone MPMoviePlayerPlaybackDidFinishNotification出现问题,iphone,Iphone,我有一个奇怪的问题。播放结束后,我需要停止播放机。我正在使用 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAudio) name:MPMoviePlayerPlaybackDidFinishNotification objec
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAudio)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
虽然播放器停止,但第一次调用stopAudio方法两次,第二次调用4次,第三次调用6次,依此类推。我不知道如何解决这个问题。我的stopAudio方法是
- (void)stopAudio {
[player pause];
[player stop];
}
我有一个自定义按钮,通过它也可以调用stopAudio方法
有什么建议吗…每次开始玩游戏时,你似乎都会加入自己作为观察者的角色。由于玩家停止时观察请求未被清除,因此观察请求的数量会增加,您会收到越来越多的通知。请确保您只注册一次,或者在玩家停止播放时使用removeObserver:或removeObserver:名称:对象:取消注册。您似乎在每次开始播放时都将自己添加为观察员。由于玩家停止时观察请求未被清除,因此观察请求的数量会增加,您会收到越来越多的通知。请确保仅注册一次,或者在播放器停止播放时使用removeObserver:或removeObserver:名称:object:取消注册。解决了问题…正如Zoul建议的那样,我在stopAudio方法中删除了观察员。我还用NSNotificationCenter中的播放器替换了nil对象。它现在工作得很好。。。桑克斯·佐尔
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAudio)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
我的stopAudio方法是:
- (void)stopAudio {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player pause];
[player stop];
}解决了这个问题……正如Zoul建议的那样,我在stopAudio方法中删除了观测者。我还用NSNotificationCenter中的播放器替换了nil对象。它现在工作得很好。。。桑克斯·佐尔
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAudio)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
我的stopAudio方法是:
- (void)stopAudio {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player pause];
[player stop];
}