Playing short sound on timer end?

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...


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.

链接地址: http://www.djcxy.com/p/67930.html

上一篇: 视图更改时停止方法

下一篇: 在定时器结束时播放短声音?