1

Is it possible to output audio only to the iOS device's headphone jack and nowhere else? (e.g. not speakers nor bluetooth)

We're experimenting on a hardware add-on that receives input as tones from the audio jack. We could try detecting whether the headphone jack is connected, but that still leaves cases when there are bluetooth audio output devices are connected – we don't want the tones to be heard in the user's bluetooth headsets or speakers.

adib
  • 8,285
  • 6
  • 52
  • 91
  • Could you achieve this (audio output only to headphone jack) ? I'm trying to achieve same thing but no success yet. – Maverick Feb 25 '16 at 08:40
  • What I need is to direct iOS voice over sound to headphone even if it's not plugged in. In other words, while my app is open, voice over sound should not go to speakers. Can you suggest something on this? The accepted answer doesn't answer my scenario. – Maverick Feb 25 '16 at 08:56
  • @maverick You mean have the headphone jack output signal even when there are no headphones connected? I have a feeling that's not going to be possible in iOS as it would need to go down to the audio driver level. AFAIK there's a physical switch that gets triggered when you put something in the jack, and that's what the driver uses to redirect output. – adib Feb 25 '16 at 09:44
  • OR if it can't direct sound to headphone jack in case it's not connected, at least mute the loud speaker in any scenario, that will also suffice my purpose. I just don't want the sound to some out of speaker (VoiceOver sound or other sounds played by myself through `AVSpeechUtterance`) while it should come through headphones, if connected. – Maverick Feb 25 '16 at 10:41

1 Answers1

6

You need read AudioSessionProgrammingGuide

You can get the current audio 'route' by calling AudioSessionGetProperty with the kAudioSessionProperty_AudioRoute property. This gives you a string such as "Headphone" or "Speaker" and play audio file receptively 'route' value

CFStringRef route;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &route);

NSLog(@"%@ %@",route,kAudioSessionInputRoute_Headphone);
NSLog(@"%ld",CFStringGetLength(route));
if ([(__bridge NSString *)route isEqualToString:@"Headphone"])
{
    // play audio sound
}
else
{
     // not play audio sound
}

I hope it help you

chandan
  • 2,453
  • 23
  • 31