CHAPTER 12: Digital Audio: Providing Aural Feedback for UI Designs Using SoundPool 469
- Inside of the .getStreamVolume( ) method, pass the AudioManager.
STREAM_MUSIC constant to establish which StreamVolume you want
to get (and then put) into your currentSoundVolume variable. This is
shown in Figure 12-23, along with a maximumSoundVolume float
variable that you are going to declare next, using a similar method call to
a .getStreamMaxVolume( ) method, using the same STREAM_MUSIC
constant. This will configure two (currently unused, as warning highlights
indicate in Figure 12-23) sound volume variables.
Figure 12-23. Add a maximumSoundVolume float variable and call a .getStreamMaxVolume( ) method off of AudioManager
- Once you have the two float variables declared and loaded with the current
and maximum audio settings for the user’s Android device, you can figure out
a percentage value (divide current volume setting by a maximum) and give
the SoundPool .play( ) method the value range (0.0 to 0.99) that it requires. Do
this using the following block of Java code (I’ll include all three statements
here, in one place), which is also shown error-free in Figure 12-24:
float currentSoundVolume = audioControl.getStreamVolume(Context.STREAM_MUSIC);
float maximumSoundVolume = audioControl.getStreamVolume(Context.STREAM_MUSIC);
float volumeSet = currentSoundVolume / maximumSoundVolume;