开发者

AVAudioPlayerdelegate

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜