Question

I have some sound that is played in a loop as a noise is registered using an AVAudioRecorder.

Here is my code:

NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"foghornRepeat2" ofType:@"aif"];
        foghornRepeat =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathToFile] error:nil];
        //foghornRepeat.delegate = self;
        [foghornRepeat prepareToPlay];

        foghornRepeat.numberOfLoops = -1;
        [foghornRepeat setVolume:1];

It is then played and stopped when sound is registered through the microphone. Any idea why this would be really quiet on an iphone? Its fine on my ipod touch.

Is there any other way I can do this?

Thanks Tom

Was it helpful?

Solution

What probably happened is that the audio on your iphone rerouted to the phone speakers. To make sure the sound plays from the real speakers, use the following code before you play a sound effect:

   UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
 AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top