I'm using the following code to play a simple clicking sound when tapping a button.
import AudioToolbox
private var clickSound: SystemSoundID!
func createSound(soundName: String) -> SystemSoundID {
var id: SystemSoundID = 0
let url = CFBundleCopyResourceURL(CFBundleGetMainBundle(), soundName, "wav", nil)
AudioServicesCreateSystemSoundID(url, &id)
return id
}
//Load click sound.
clickSound = createSound("ButtonClick")
This works, but he first time I tap a button, the sound is delayed a bit. All subsequent button taps result in the sound playing immediately. It leads me to believe that the sound is not loaded until the first time it's played.
Is there any way to get rid of this delay?