Quote:
Originally Posted by BillyGiggles
When i play a sound using the code..
Code:
- (IBAction)JazzBass{
NSString *path = [[NSBundle mainBundle] pathForResource:@"JazzBass" ofType:@"mp3"];
AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
}
The warning is on the line that says..
Code:
theAudio.delegate = self;
The warning is..
warning: class 'jazzDrumsCowbellLeft' does not implement the 'AVAudioPlayerDelegate' protocol
Any one know how to fix it?
thanks
|
The compiler is telling you exactly what you need to do. The jazzDrumsCowbellLeft class needs to implement the AVAudioPlayerDelegate protocol. To add a protocol to an object, you need to do a couple of things. First, add the protocol to the interface for your class, like this:
@interface jazzDrumsCowbellLeft : parentClass <AVAudioPlayerDelegate>
Replace "parentClass" with whatever class your jazzDrumsCowbellLeft class inherits from.
The protocol(s) your class supports go inside the angle brackets, separated by commas. In this case we're only listing one protocol, AVAudioPlayerDelegate.
The next step is to look up the AVAudioPlayerDelegate protocol in the XCode docs and see what methods you need to implement to support that protocol.
Checking the docs, it says:
"The delegate of an AVAudioPlayer object must adopt the AVAudioPlayerDelegate protocol.
All of the methods in this protocol are optional. They allow a delegate to respond to audio interruptions and audio decoding errors, and to the completion of a sound’s playback."
Since all the methods are optional, you don't HAVE to implement any of them. The audioPlayerDidFinishPlaying:successfully: is probably the most useful delegate method - it lets you get notified when the sound finishes playing. This would let you play a list of sounds one right after the other, for example.