Simple sound effect loop using AudioToolKit
- by Typeoneerror
I've created a few sounds for use in my game. I can play them at certain events without issue:
// create sounds
CFBundleRef mainBundle;
mainBundle = CFBundleGetMainBundle();
_soundFileShake = CFBundleCopyResourceURL(mainBundle, CFSTR("shake"), CFSTR("wav"), NULL);
AudioServicesCreateSystemSoundID(_soundFileShake, &_soundIdShake);
// later...
AudioServicesPlaySystemSound(_soundIdShake);
The game has a mechanism which allows you to shake the device to activate some functionality. I've got the shaking code done so I get get a "shaking started" and "shaking ended" message to my game. What I need to have happen is start playing "shave.wav" when shaking starts and loop it until it stops. Is there a way to do this with AudioToolbox/AudioServices? How could I do this if not?