Search code examples
androidvolumesoundpool

Android - Control SoundPool's volume with hardware volume buttons?


I made an app which has several sounds implemented with soundPool, like sounds when user is pressing buttons etc.

But they are short, so if i press hardware button "volume -" on my phone - of course, my phone volumes down sound of incoming calls and not the sound of my SoundPool(I'm not sure if this is the same volume as MediaPlayer uses).

How can I lock my phone's volume hardware buttons (or any volume controls buttons) so by pressing them I could adjust SoundPoool's volume?


Solution

  • Use setVolumeControlStream() to "bind" volume keys to audio stream you use in your app.