What is the difference between AudioManager's

2019-02-13 18:01发布

There are several stream types in AudioManager. How did they differ at low level? Could it be that usage of e.g. AudioManager.STREAM_MUSIC blocks input microphone stream? Or something else?

3条回答
手持菜刀,她持情操
2楼-- · 2019-02-13 18:15

One most significant difference is a volume control.
As the document says, we can set a volume level or adjust a volume for each streams respectively.
And we can control "Audio Focus" that let other apps stop playback or lower the volumes so we can play a sound clearly on a specific stream, or the sound will not block the other high-prioritized sound like phone ring, navigation voice feedback or something like that.

With multiple apps potentially playing audio it's important to think about how they should interact. To avoid every music app playing at the same time, Android uses audio focus to moderate audio playback—only apps that hold the audio focus should play audio.

Other unmentioned thing is which audio device will produce a sound.
Using STREAM_MUSIC the sound will be produced through one audio device(phone speaker, earphone, bluetooth speaker or something else) connected to the phone.
Using STREAM_RING the sound will be produced through all audio device connected to the phone. This behaviour might be differed for each devices.

查看更多
迷人小祖宗
3楼-- · 2019-02-13 18:17

As usual, whatever you Google won't document can (sometimes) be understood from the code

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

As for blocking, it's not really that streams block one another, it's just that modes block things. MODE_IN_COMMUNICATION blocks most of the streams.

Ducking: A common and "polite" behaviour when playing a long running stream (e.g. MUSIC) is to listen to an audio focus callback and lower the volume of your stream manually upon "can duck" event. The volume should return to its previous level when the focus returns to your stream.

查看更多
Bombasti
4楼-- · 2019-02-13 18:22
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

查看更多
登录 后发表回答