12

I am encountering the following problem: AirPlay becomes not available whenever I set play-and-record category to the audio session in my application:

[[AVAudioSession sharedInstance]
        setCategory: AVAudioSessionCategoryPlayAndRecord
        error: &setCategoryError];

This call makes the AirPlay disappear and reroutes the audio to the speaker immediately.

The problem can be easily reproduced e.g. on the sample project avTouch from Xcode documentation by replacing AVAudioSessionCategoryPlayback category with AVAudioSessionCategoryPlayAndRecord: in the original example AirPlay picker is visible and allows to change output source, whereas with the AVAudioSessionCategoryPlayAndRecord category the picker disappears.

Is there a proper way to switch to AVAudioSessionCategoryPlayAndRecord category so that the AirPlay is still available?

(A question like this has been already asked, but didn't get any answer.)

Community
  • 1
  • 1
Anastasia
  • 3,024
  • 1
  • 23
  • 34
  • Probably you might have to try with some private APIs. Check if this helps in anyway. http://spin.atomicobject.com/2012/04/23/ios-mirroring-and-programmatic-airplay-selection/ They are mentioning some private apis. – iDev Nov 01 '12 at 23:49
  • 1
    @ACB: thank you! I looked at the mentioned article, but as you say, they are using private APIs, which I cannot use, as the project I am working for is distributed through App Store. – Anastasia Nov 04 '12 at 20:14
  • @Anastasia Have you got an solution? I'm facing the same issue with you.Thanks – LiangWang Mar 17 '14 at 04:05
  • @Jacky No, I have no solution. Jonathan Arbogast's idea sounds likely though. – Anastasia Mar 17 '14 at 11:51

3 Answers3

1

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
0

I think you should add the code below above AVAudioSession. I hope it works.

NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error: &setCategoryError];

if (setCategoryError) {
    // Handle error
}
s1m0n
  • 7,825
  • 1
  • 32
  • 45
-1

Well, AirPlay and the PlayAndRecord category are just incompatible. That's what I learned from the Apple forums.

Why do you need audio input on the device when audio output happens somewhere else?

smk
  • 94
  • 6
  • 1
    The application plays back a video stream (possibly outputting the sound through AirPlay) and records the said stream at the same time. Makes sense? – Anastasia Nov 05 '12 at 22:21
  • The point is, the audio works as expected for plugged-in headphones, so it was my natural assumption that AirPlay-connected headphones should work the same way. – Anastasia Nov 05 '12 at 22:26
  • -1: There are so many reasons why you might want it. A customer of mine wishes to use my audio monitoring software to perform a room response check by playing out audio over airplay and then monitoring what the iPhone records (in measurement mode). So annoying that apple block this completely. – Goz Apr 11 '14 at 08:20