Soundboard app: Play sound as long as the user is pressing the button
- by Pantelis Proios
I am making a soundboard app and i am using sounds with over 30sec duration. I am playing the sound by connecting in IB my action with a "touch down" event, however the sound keeps playing once started. I connected in the some button a "touch cancel" & "touch up outside" event that is supposed to stop the sound but for some reason it doesn't.
Can anybody provide a solution to my problem?
---Edit---
Here is my code:
-(IBAction)playSound:(id)sender {
NSString *soundFile;
soundFile = [[NSBundle mainBundle] pathForResource:@"testSound" ofType:@"mp3"];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundFile] error:nil];
audioPlayer.volume = volumeSlider.value;
audioPlayer.numberOfLoops = -1;
[audioPlayer prepareToPlay];
[audioPlayer play];
}
-(IBAction)stopSound:(id)sender {
[audioPlayer stop];
}