Reputation: 23
Im planing on using this code to make random sounds play with an action, not exactly sure on how to name my sound files. Thanks for any help.
int randomNumber = arc4random() % 24 + 1;
NSURL *soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"Sound%02d", randomNumber] ofType:@"mp3"]];
AVAudioPlayer * soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];
[soundPlayer prepareToPlay];
[soundPlayer play];
Upvotes: 1
Views: 992