views:

58

answers:

1

Hello,

I receive this error for this code-

warning: class 'BeatMaker' does not implement the 'AVAudioPlayerDelegate' protocol

-(IBAction)playBeat3 {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"beat3" ofType:@"mp3"];
    AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; 
    theAudio.delegate = self;
    [theAudio play];                         
}

Can anyone help me with this?

+1  A: 

You've told your AVAudioPlayer instance that your BeatMaker class implements the AVAudioPlayerDelegate protocol with this line:

theAudio.delegate = self;

But apparently your BeatMaker class hasn't told the compiler that it is actually an AVAudioPlayerDelegate. You would do that in the header file:

@interface BeatMaker : NSObject <AVAudioPlayerDelegate> { ... }

Then you would have to make sure that you have implemented all the required functions of the AVAudioPlayerDelegate protocol in your BeatMaker class.

In this case, there are no required functions for the protocol, so if you are just copying code and you don't actually want to recieve messages from theAudio, you can just delete the line assigning self to the delegate property of theAudio.

Seamus Campbell
Thanks! Fixed my problem!
Henry D'Andrea