34

My app uses the microphone and outputs audio, so I am setting my Audio Session to the Play and Record Category, but this seems to disable Airplay. If I set the category to Play, Airplay works fine with my output (but obviously the input doesn't work).

I've tried overriding the output route to speaker, in case it needed that to output over Airplay, but no joy.

Any ideas?

thf_dave
  • 383
  • 3
  • 7

4 Answers4

3

What AirPlay device are you trying to use? Does it have a microphone?

If not, iOS won't present it as an option when using the PlayAndRecord category, because that device can't play and record. It would show up when using the Play category though.

Also, if the device you are using is a Bluetooth device, have you set AVAudioSessionCategoryOptionAllowBluetooth to YES?

Jonathan Arbogast
  • 9,620
  • 4
  • 35
  • 47
1

From the Audio Session Programming Guide › Working with Categories › Choosing Categories and Modes for AirPlay:

Only specific categories and modes support AirPlay. The following categories support both the mirrored and non-mirrored versions of Airplay:

  • AVAudioSessionCategorySoloAmbient
  • AVAudioSessionCategoryAmbient
  • AVAudioSessionCategoryPlayback

The AVAudioSessionCategoryPlayAndRecord category only supports mirrored Airplay.

Marián Černý
  • 15,096
  • 4
  • 70
  • 83
0

If you want to change where the audio is going you need to call AudioSessionSetProperty, and pass it the constant specifying where you want the audio to go. These constants are

kAudioSessionOverrideAudioRoute_None, which specifies that you wish the audio to be routed to the receiver (the airplay if that's where it is going), or

kAudioSessionOverrideAudioRoute_Speaker, which specifies that audio should be routed to the speaker at the bottom of the phone.

Cameron
  • 383
  • 3
  • 11
0

You can try this code

// Set AVAudioSession
NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError];

// Change the default output audio route
UInt32 doChangeDefaultRoute = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
  sizeof(doChangeDefaultRoute), &doChangeDefaultRoute);
Karthick
  • 382
  • 1
  • 3
  • 23