views:

169

answers:

1

It appears that AVAudioPlayer is not reentent. So in the following would soundfx play to completion, delay 1 second, then play again, rather then the 1 second delay - and resultant overlapping playback I desire:

// ...

AVAudioPlayer* soundfx = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];


(void) makeSomeNoise {

  [soundfx play];
  sleep(1);
  [soundfx play];


}

Must I then resort to NSOperation - threading - to achieve my goal of overlapping playback?

Note: I am using IMA4/ADPCM format which is apparently the correct format for layered sound playback.

Cheers, Doug

A: 

It's not that AVAudioPlayer is not reentrant. It is that AVAudioPlayer starts to play your sound after the runloop has ended, and not in your makeSomeNoise function. If you want to play your sound with a one second delay, you can do this:

(void) makeSomeNoise {
  [soundfx play];
  [soundfx performSelector:play withObject: nil afterDelay:1.0];
}
mahboudz