I’m making an app which both needs to play ‘tap’ generated system sounds and to record user inputted sound to trigger an event. The sounds, which are triggered by the UITapGestureRecognizer play SystemSounds via the SoundEffect Class, whilst the recorder uses the AVAudioSession Class.
The audio was working fine in the simulator, but when played on my iPhone all sound was diverted to the receiver ( that’s the small telephone speaker at the top rather than the larger speaker by the dock-connector), which is much quieter.
Source of the Solution
The solution was found here: problem with AVAudioSession and Voice Recording
“When you start recording on an iPhone the audio will switch from the main speaker to the in call speaker which has lower volume, you need to redirect the audio route. “( From Steve Oldmeadow)
The Audio Session Programming Guide in the iOS developer documentation lists the solution:
“..Changing the default output route. … This option is available starting in iOS 3.1…“
I’ll paste the code snippet here:
// need to import now
//Instanciate an instance of the AVAudioSession object.
AVAudioSession * audioSession = [AVAudioSession sharedInstance];
//Setup the audioSession for playback and record.
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error];
//Activate the session
[audioSession setActive:YES error: &error];
// change the default output
UInt32 doChangeDefaultRoute = 1;
Hopefully this post will be good for my own future refrence and perhaps to others.