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

Audio dev questions

tr00don

Lurker
Hi all, I’m new to Android and I would greatly appreciate some input on the following audio-related questions:

1. Is there anything that I need to do for my app to send audio to the wired headphones or external speaker when connected, instead of the internal speaker? My app uses AudioTrack.Play to play a beep. It always plays through the built-in speaker, even when I plug in headphones, wired or wireless. I think some additional control is possible through the Usage and ContentType fields but it's not clear to me how.

2. Same question as above but specifically for the case when the smartphone is connected to a Bluetooth speaker.

3. Same questions as above but for audio input (i.e., do I need to programmaticaly read audio from a connected wired or wireless microphone or is the system supposed to switch to these external devices automatically when they are connected?)

I am aware of the requirement to request and obtain the Bluetooth permission in order to access such devices but I am confused because other apps do play audio to my Bluetooth speaker, apparently without requiring any Bluetooth permission. What am I missing here?

Any help is greatly appreciated.
 
Last edited:
Is there anything that I need to do for my app to send audio to the wired headphones or external speaker when connected, instead of the internal speaker?

Really? I'm surprised that's the behaviour you're seeing.
Does that happen with any music player?
 
Using the AudibilityEnforced flag in the AudioAttributes builder the track always plays through the built-in speaker and its duration can be as short as 1 ms.

Without using the AudibilityEnforced flag, the track does play through the connected Bluetooth speaker but it is audible/detectable only if its duration is at least 20 ms. This could be a limitation of the Bluetooth device. Also, it seems the media audio volume is sometims automatically set to zero for some reason; using audioManager.setStreamVolume for music in OnResume helps to prevent this.

Interestingly, when recording audio there appears to be an initial refractory period of about 20 ms.
 
Last edited:
Back
Top Bottom