• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Usb attached device with 2 audio ports

Hello,

I'm developing a streaming music application. I connected via Usb a controller that have 2 audio ports (2 x Jack 3.5mm): one for speakers and one for headphones.
Android automatically detect the audio port for speakers as default. When I plugg in some speakers or headphones in the speakers port(default), the apps runs well and the music is heard.
When I plugg in the second port some headphones, the music isn't heard.

My question is: is it possible to find/get all audio ports from an Usb attached device to redirect the audio output in these 2 ports simultaneously?
 
Yes, it is possible to get all audio ports from an USB attached device. You can use Android's AudioManager class to access each port and configure the routing of the audio accordingly. You can also use audio APIs such as OpenSL ES to access the audio ports. From there, you can use the Audio Routes API to route the audio to multiple destinations. Additionally, you should take a look at some 3rd party libraries that provide more options for audio routing, such as the Audio Jack library.
Thank you for your response.

I used getDevice() method from AudioManager when my controller was connected to my Samsung Galaxy Tab S8 and it has 3 devices: first is Type 2(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER), second is Type 11(AudioDeviceInfo.TYPE_USB_DEVICE) and the third Type 18(AudioDeviceInfo.TYPE_TELEPHONY). After connection, the selected device is Type 11 and the music is heard in the master port(automatically default selected by Android).

When I plugg in headphones in the headphones port, nothing changed in the AudioManager and I have the same 3 output devices.

I mention that I have tested the controller with a DJ software on PC and the headphones port worked fine.


I will try to use OpenSL ES API to get a solution., maybe it will work.
 
  • Like
Reactions: osmanjames
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones