Skip to content

Instantly share code, notes, and snippets.

@nummi
Created September 9, 2010 23:18
Show Gist options
  • Save nummi/572762 to your computer and use it in GitHub Desktop.
Save nummi/572762 to your computer and use it in GitHub Desktop.
-(void) playSound:(NSString *)fileName {
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"aif"];
NSError* err;
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:filePath] error:&err];
player.delegate = self;
[player play];
}
-(void) playCricket { [self playSound:@"cricket"]; }
-(void) playTrombone { [self playSound:@"trombone"]; }
-(void) playRimshot { [self playSound:@"rimshot"]; }
#pragma mark -
#pragma mark AVAudioPlayer Delegate Methods
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)aplayer successfully:(BOOL)flag {
// Considered sloppy. Would cause issues with GC.
// Create mutable array of players and pop off from this delegate method?
[aplayer release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment