AudioToolBox how to make sound repeat

I used these codes so that my app plays sound when I turn on the switch:

-(IBAction)play:(id)sender{
    if (_soundSwitch.on) {
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"my sound name", CFSTR ("wav"), NULL);
        UInt32 soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesPlaySystemSound(soundID);
       
    }else
    {
        //I didn't write any code here
    }
}

And it works. But the sound doesn't repeat and if I turn it off, the sound is still playing. Can anyone please tell me how to make the sound repeat and able to stop it when I switch it off or give me sample code? Thanks

Have you taken a look at AVAudioPlayer, seems like that's a good candidate API for what you're looking for. AudioServices is really meant to be used for SystemSounds/Alerts.

AudioToolBox how to make sound repeat
 
 
Q