Hello, I have some UIImageViews (Animals) and by touching them a specific soundloop starts to play. But if the user touches twice or more on the same View, the apropriate soundloop starts over and over again with an overlap. I wanna have that the touched sound is played once until its end and than the user can start the next time. The duration of a soundloop is approx. 3 sec.I tried something with "sleep(3); but it stops the prog before the sound is playing..
But if the user touches another View, two different sounds can overlap.
#pragma mark -
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
//Soundfile names in array arrAnimalde
arrAnimalde = [NSArray arrayWithObjects:@"Hund" ,@"Schwein" ,@"Ferkel", nil];
// here are some Views and their triggers
if([touch view] == img_hund){
trigAnimal = 0;
}
if([touch view] == img_schwein){
trigAnimal = 1;
}
if([touch view] == img_ferkel){
trigAnimal = 2;
}
AudioServicesCreateSystemSoundID ((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: [arrAnimalde objectAtIndex: trigAnimal]
ofType: @"wav"]], &soundFileObject);
AudioServicesPlaySystemSound (self.soundFileObject);
//if the trigger is the same as before play the sound only once and completely
}
}
Please write alternative solutions too - maybe with the possibilities to start and hold the sound in every if-statement.
Thanxx