Objective-c – Playing short sound on timer end

iphoneobjective c

In my app I have a timer that counts down, and when it stops an image is displayed and a sound is played.

The sound is loaded like this:

NSString *path = [[NSBundle mainBundle] pathForResource:@"scream" ofType:@"wav"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);

And Played like this on timer end:

AudioServicesPlaySystemSound(soundID);

My problem is that the sound doesn't get played on time. Even though the sound instance is called before the image, the image appears before the sound. This only occurs the first time the sound is played. The sound is loaded in the viewDidLoad method.

Is there a better way to do it, or what am I doing wrong?

Thanks…

Best Answer

Maybe the sound is delayed while the speaker is powered up (for the first sound). If so, maybe you can work around it by playing a different, unnoticeable sound earlier so that the speaker is ready to go when you request the "real" sound.

Related Topic