I have an iPhone app where I play a sound when the user is taking a test. Works great except for the first time the sound plays when there is a delay, I assume loading the sound into memory. How can I preload the sound? Here is my code for the sound:
- (void)doBuzz:(id)sender {
SystemSoundID buzzsoundID;
NSString *buzzsoundFile = [[NSBundle mainBundle]
pathForResource:@"buzz" ofType:@"caf"];
AudioServicesCreateSystemSoundID((CFURLRef)
[NSURL fileURLWithPath:buzzsoundFile]
, &buzzsoundID);
AudioServicesPlaySystemSound(buzzsoundID);
}
I fixed my sound delay problem by moving my declaration for the SystemSoundID into the .h file of my UIViewController and then set the NSString and called AudioServicesCreateSystemSoundID from ViewDidLoad. Then when I wanted to play the sound, rather than calling the doBuzz method I simply replaced that with AudioServicesPlaySystemSound.