In my application, I have buttons setup as a keyboard. Each buttons acts similar to a piano key, where you touch the button and the sound plays when you hold but stops when you release. For this method, I am using two IBActions. One for Touch Down (Sound Play) and Touch Up Inside (Sound Stop). I am using SystemSoundID for playing the sounds, as AVAudioPlayer has a delayed play. The only problem is, when I hold down the button the sound plays fine, but once I release the touch my app crashes. Below is my Code:
.h File:
SystemSoundID *soundID;
.m File:
- (IBAction)ASoundStart:(id)sender {
NSString *soundFile = [[NSBundle mainBundle] pathForResource:@"P1:4t" ofType:@"mp3"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID);
AudioServicesPlaySystemSound(soundID);
[soundFile release];
}
- (IBAction)ASoundStop:(id)sender {
AudioServicesDisposeSystemSoundID(soundID);
}