1

I want to repeat the sounds that are send to this method?

- (void) playSound:(CFURLRef)soundFileURLRef {
    SystemSoundID soundID;
    OSStatus errorCode = AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    if (errorCode != 0) {

    }else{
        AudioServicesPlaySystemSound(soundID);
    }
}

I've seen answers on how this is made using numberOfRepeats. But I can't fit it in my code.

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
John Wilund
  • 339
  • 4
  • 13

1 Answers1

0

Try using AVAudioPlayer:

- (void) playSound:(CFURLRef)soundFileURLRef {
    NSError* sndErr;        
    AVAudioPlayer *player = [[ AVAudioPlayer alloc ] initWithContentsOfURL:(NSURL *)soundFileURLRef error:(&sndErr) ];

    // at this point player has a retain count of 1. you should save it 
    // somewhere like a class member variable so you can stop the playing
    // and release the object later. Under ARC, you must have a strong reference
    // to the object so that it doesn't get released when this function goes out
    // of scope.

    if (sndErr != nil) {
        player.numberOfLoops = -1; // infinite number of loops. call stop when you want to stop.
        [player play];
    }
}
kamprath
  • 2,220
  • 1
  • 23
  • 28