Possible to detect headset?


#1

Howdy

Is it possible to detect wheter a headset is plugged into the device on iOS?


#2

Yep, that info is buried inside the kAudioSessionProperty_AudioRouteDescription property (get to this using the AudioSessionGetProperty call)

The input type (built-in mic / line in / headset mic etc) is found in the kAudioSession_AudioRouteKey_Inputs dictionary within the property.

Likewise, the output type (built in speaker / headphones etc) is found in kAudioSession_AudioRouteKey_Outputs dictionary.


#3

Thanks for this.

So how do you actually get to this data in say the process block? I am not finding any Juce documentation for AudioSessionGetProperty which looks to be an apple thing (and maybe deprecated?).

 

I see the handy iosAudioIODevice.cpp file in the modules / native folder, but how do I get to it? I tried just copying the contents into another file but it's throwing a bunch of errors ... cant find things like AudioUnit, etc. etc.

 

Any pointers appreciated while I dig around.


#4

This info is not available via Juce, it's all accessed via Apple APIs.

You're correct that AudioSessionGetProperty is deprecated (but available). It's been superseded by the AVAudioSession Obj-C class. Looks like the currentRoute property contains the info you're after.

You need to add the AVFoundation framework to your Juce project in order to access this Apple API.


#5

Thanks daveb

That is what thought - I've added the AVFoundation framework via the 'Linked Frameworks and Librarys' field in xcode. I've also added 'AVFoundation' to the list of extra frameworks in the introjucer.

I've also added 'AudioToolbox' the same way.

 

 

Is there anything else I need to add/include in my code or the introjucer to access the framework? Things like 'AudioSessionPropertyID' are still showing up as unknown...though I can cmd-click the term to take me to the definition.

 


#6

Howdy

Just wondering if I could get some pointers on this.

I've included the frameworks via the IntroJucer like so: Accelerate, AVFoundation, AudioToolbox
...and I've also included them via xCode.

I'm still getting some errors, mainly in NSObjCRuntime.h - things like 'Unknown Type Name: NSString', 'Unknown Type Name: Protocol'....etc

 

I guess I'm just sort of at a loss as to where to include the iOSAudioIODevice... currently I have just copy/pasted the code into another header file, after the code in there likeso:

/* juce_standalonefilterwindow.h code...... */

#include <AudioToolbox/AudioToolbox.h>
#include <AVFoundation/AVFoundation.h>

class iOSAudioIODevice  : public AudioIODevice....

 

Thanks for any pointers - if there is some example of using iOS native audio somewhere, please let me know.