Android 7.0 (Nougat, API 24) introduced some extra methods to allow you to obtain an AudioRouting object (which will allow you to get the audio device which is currently in use) from OpenSL by using the AcquireJavaProxy method.
Here’s how:
-
When creating your OpenSL player include the
SL_IID_ANDROIDCONFIGURATIONinterface -
Once the player is realized obtain the configuration interface:
SLresult result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_ANDROIDCONFIGURATION, &configItf); -
Use the configuration interface to obtain the AudioRouting handle
SLresult result = (*configItf)->AcquireJavaProxy(configItf, SL_ANDROID_JAVA_PROXY_ROUTING, &routingObj); -
Pass this back to Java (or do some JNI hackery) to obtain an
AudioRoutingobject -
Call
AudioRouting.getRoutedDevice()to obtain anAudioDeviceInfoobject
Example app here: https://android.googlesource.com/platform/cts/+/master/tests/tests/media/libndkaudio
