When I press a button, then press another one, the sounds overlap. How can I fix that so the first sound stops when another one is pressed?
- (void)playOnce
In your playOnce method the 'path' variable is unused -- remove that to get rid of your warning message. Your playOnce does not set anything up to play so I'm not sure how that is supposed to work -- unless you call playLooped first? You also need to be calling prepareToPlay after the initWithContentsOfUrl.
- (void)playOnce:(NSString *)aSound {
NSString *path = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"];
if (theAudio && [theAudio isPlaying]) {
[theAudio stop]
} else {
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath: path] error: NULL];
[theAudio prepareToPlay];
[theAudio setDelegate: self];
[theAudio setNumberOfLoops: 1];
[theAudio setVolume: 1.0];
[theAudio play];
}
}