Reputation: 1889
Quick question: Is it possible to set the delegate of an AVAudioPlayer instance to more than one class?
In my program, I want two classes to be notified when a sound has been finished playing, but I am unsure of how to do that.
Any help would be appreciated.
Upvotes: 0
Views: 453
Reputation: 7102
Well it is something not possible. but you can do it by registering and notifying notification. Here is code for registering and notifying classes in objective c.
So you can set one class a delegate and there you can notify other classes
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
NSLog(@"delegate called");
[[NSNotificationCenter defaultCenter]
postNotificationName:AUDIO_PLAYER_FINISHED_PLAYING object:nil];
}
Upvotes: 1
Reputation: 1682
No, a delegate is always just one instance. You could make a new class that is the delegate and make it send an NSNotification to notify the other two classes about the event.
Upvotes: 0