Problem with MPMoviePlayerPlaybackDidFinishNotification
I am having a strange problem. I need to stop the player when playback finishes. I am using
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAudio)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
Though the player stops but for the first time stopAudio mehod is called twice, 2nd time it is called 4 times, 3rd time it is call开发者_JS百科ed 6 times and so on. I don't know how to tackle this problem. My stopAudio method is
- (void)stopAudio {
[player pause];
[player stop];
}
I do have a custom button via which also the stopAudio method can be called.
Any suggestions Plz...
You seem to add yourself as the observer each time you start playing. Since the observation request is not cleared when the player stops, the number of observation requests grows and you get more and more notifications. Either make sure you register only once or unregister using removeObserver:
or removeObserver:name:object:
when the player stops playing.
Solved the problem...as Zoul suggested I removed the observer inside the stopAudio method. I also replaced the nil object by the player in the NSNotificationCenter. It is working fine now... Thanx Zoul
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAudio)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
my stopAudio method is :
- (void)stopAudio {
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[player pause];
[player stop];
}
精彩评论