I need to insert a code, in function, that when called play a sound.
The problem is that the function is called faster than sound duration and so, the sound is played less times than function calls.
function keyDownSound(){
NSSound(named: "tennis")?.play()
}
The problem is that NSSound starts playing only if isn't already played. Any ideas to fix?
Source of problem is that
init?(named name: String)return sameNSSoundinstance for same name. You can copyNSSoundinstance, then several sounds will play simultaneously:Alternative way - start sound again after finish playing. For that you need to implement
sound(sound: NSSound, didFinishPlaying aBool: Bool)delegate method. For example: