What is the difference between AudioManager stream types at a low level?

There are several types of streams in AudioManager . How did they differ at a low level? Could it be that using, for example, AudioManager.STREAM_MUSIC blocks the microphone input? Or something else?

+6
source share
3 answers

One of the most significant differences is volume control.
As stated in, we can set the volume level or adjust the volume for each stream, respectively.
And we can control the โ€œFocus of soundโ€ so that other applications stop playing or lowering volumes, so that we can clearly reproduce sound on a specific stream, or the sound will not be blocked by other high-priority sound, such as a phone ring, voice feedback from navigation or whatever something like that.

With several applications that potentially play audio, it's important to think about how they should interact. To avoid the simultaneous use of any music application, Android uses audio focus for moderate sound reproduction. Applications that perform audio focus must play audio.

Another non-interference is which sound device will produce the sound.
Using STREAM_MUSIC, the sound will be played through one audio device (phone speaker, earphone, bluetooth speaker or something else) connected to the phone.
Using STREAM_RING, sound will be played through all audio devices connected to the phone. This behavior may vary for each device.

+7
source

As usual, no matter what you Google will not document, it can (sometimes) be understood from the code

https://android.googlesource.com/platform/frameworks/base/+/00ccd5d026fcd0e4b9d27dc5a9ffa13ca0408449/media/java/android/media/AudioService.java

As for blocking, this does not mean that threads are blocking each other, it's just that modes block things. MODE_IN_COMMUNICATION blocks most threads.

duckling: A common and โ€œpoliteโ€ behavior when playing a long stream (such as MUSIC) is to listen to the sound focus callback and manually decrease the volume of your stream after the โ€œcan duckโ€ event. Volume returns to its previous level when focus returns to your flow.

+3
source
STREAM_ALARM The audio stream for alarms STREAM_DTMF The audio stream for DTMF Tones STREAM_MUSIC The audio stream for music playback STREAM_NOTIFICATION The audio stream for notifications STREAM_RING The audio stream for the phone ring STREAM_SYSTEM The audio stream for system sounds STREAM_VOICE_CALL The audio stream for phone calls 

from http://developer.android.com/reference/android/media/AudioManager.html

+2
source

Source: https://habr.com/ru/post/971972/


All Articles