views:

1150

answers:

5

It seems that it's not possible to play an alert sound

AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);

while the AudioQueue is being used to record audio. Is that correct? Maybe I'm doing something wrong. Is there a way to do this other than pausing the recording?

TIA.

A: 

Just a wild guess, but is your audio session set to kAudioSessionCategory_PlayAndRecord?

Rhythmic Fistman
Ok. So I added this to the AudioQueue initialization code: UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord; AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), but I still have the same issue, e.g. playalertsound doesn't cause the device to vibrate while it's recording. Any other thoughts?Thanks.
Matt Long
+2  A: 

From reading Apple's developer forums, a couple devs claim this is a bug that's been filed. If you set your session type to kAudioSessionCategory_PlayAndRecord it ought to work.. but doesn't.

justinb
I will award this one to you if you'll referece the forum post you're referring to.
Matt Long
The specific post is:https://devforums.apple.com/message/79080
justinb
A: 

Try this:

UInt32 category = kAudioSessionCategory_PlayAndRecord; 
status |= AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
UInt32 allowMixing = true;
status |= AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers,   // 1
                                  sizeof(allowMixing),                                   // 2
                                  &allowMixing);                                         // 3
status |= AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck,    // 1
                                  sizeof(allowMixing),                                  // 2
                                  &allowMixing);                                        // 3

The final two AudioSessionSetProperty calls are new in the 3.0 OS. These enable me to play sounds as well as vibrate during recording.

sehugg
+1  A: 

I tried what sehugg suggested but no luck? Do you active it like this?

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];
UInt32 doSetProperty = 1;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty);
AudioSessionSetProperty (kAudioSessionProperty_OtherMixableAudioShouldDuck, sizeof(doSetProperty), &doSetProperty);
[[AVAudioSession sharedInstance] setActive: YES error: nil];
Raymond Lo
A: 

The sound is really quiet because the SDK routes the sound through the earpiece speaker when you activate the VAudioSessionCategoryPlayAndRecord. This is presumably to prevent feedback in the recording. You have to manually override the audio route when in PlayAndRecord mode to send the output to the loudspeaker again. Something like this:

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, 
                                   sizeof(UInt32), &audioRouteOverride);
Gareth Clarke