stream volume in SoundPool vs volume in AudioManager

会有一股神秘感。 提交于 2019-11-29 06:15:03

问题


I am so confused...

SoundPool.play(int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)

volume here is from 0.0 to 1.0

Tutorials I've seen recommend to calculate stream volume as:

AudioManager mgr = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);

int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);

streamVolume = streamVolume / AudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);

which makes sense.

I would assume that this volume would override global media volume set by user in phone and I can change volume for my app independently by changing stream volume in soundPool.

But in reality it works like multiplier - if I set 0.5 for volume in soundpool, the actual volume will be always half of the global one. Very easy to reproduce:

  1. set global media volume in phone settings to max
  2. set volume in activity using soundpool.play to 0.5 - play sound
  3. set volume in soundpool.play to 1 - play sound, it will be two times louder

Can somebody explain why it works like that? is volume passed to SoundPool.play method really a multiplier to the global volume?


回答1:


Yes, the volume parameters are with respect to the global volume. If you want to play a sound at the current volume setting just pass "1" as the volume.



来源:https://stackoverflow.com/questions/4180960/stream-volume-in-soundpool-vs-volume-in-audiomanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!