- (void)viewDidLoad {
[super viewDidLoad];
[self initPlayers];
}
- (void)initPlayers{
NSString *p;
NSURL *f;
NSArray *snd;
AVAudioPlayer *a;
snd = [NSArray arrayWithObjects:@"file01",@"file02",@"file03",@"file04",@"file05",
@"file06",@"file07",@"file08", @"file09", @"file10", @"file11",
@"file12",@"file13", @"file14", @"file15", nil];
players = [[NSMutableArray alloc]init];
for (int i = 0; i < 15; i++) {
p = [[NSBundle mainBundle]pathForResource:[snd objectAtIndex:i]ofType:@"wav"];
f = [[NSURL alloc]initFileURLWithPath:p];
a = [[AVAudioPlayer alloc]initWithContentsOfURL:f error:nil];
[a setDelegate:self];
[a prepareToPlay];
[players addObject:a];
[f release];
[a release];
}
}
- (IBAction)buttonPressed:(id)sender
{
AVAudioPlayer *soundPlayer;
int i = [sender tag] - 1;
soundPlayer = [players objectAtIndex:i];
soundPlayer.numberOfLoops = -1;
[soundPlayer play];
}
- (IBAction)buttonReleased:(id)sender
{
AVAudioPlayer *soundPlayer;
int i = [sender tag] - 1;
soundPlayer = [players objectAtIndex:i];
soundPlayer.numberOfLoops = 0;
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)audioPlayer successfully:(BOOL)flag
{
[audioPlayer prepareToPlay];
}