views:

30

answers:

0

I'm trying to detect input from the mic and also play sounds, which can be toggled on or off, but are always playing when the mic listener is active.

I've initialized my AVAudioSession in the viewDidLoad method like so:

AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *err = nil;
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&err];
[session setActive:YES error:&err];

Then setup the sound that's supposed to be played:

NSURL *activeUrl = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audio_file.caf", [[NSBundle mainBundle] resourcePath]]];
activePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:activeUrl error:nil];
activePlayer.numberOfLoops = -1;
activePlayer.currentTime = 0;
activePlayer.volume = -1.5;

And I'm using the SCListener class to do the recording. When I run this on the phone, the recorder works just fine, but the sound won't loop even when I call play for it in the viewDidLoad method.

Any ideas?