I have a \"Utility\" class that implements the AVAudioPlayerDelegate protocol.
This is my Utility.h
@i
You've declared your method as a class method, and you're trying to use the Class object as the delegate. But you can't add protocols to Class objects.
You need to change playAudioFromFileName:...
to an instance method and create an instance of Utility
to use as the delegate. Maybe you want to have a single instance of Utility
shared by all callers. This is the Singleton pattern, and it's pretty common in Cocoa. You do something like this:
@interface Utility : NSObject
+ (Utility *)sharedUtility;
@end
@implementation Utility
+ (Utility *)sharedUtility
{
static Utility *theUtility;
@synchronized(self) {
if (!theUtility)
theUtility = [[self alloc] init];
}
return theUtility;
}
- (void)playAudioFromFileName:(NSString *)name ofType:(NSString *)type withPlayerFinishCallback:(SEL)callback onObject:(id)callbackObject
{
...
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: [self getResourceURLForName:name ofType:type] error: nil];
audioPlayer.delegate = self;
...
}
@end
[[Utility sharedUtility] playAudioFromFileName:@"quack" ofType:"mp3" withPlayerFinishCallback:@selector(doneQuacking:) onObject:duck];