A (175)

(Tuis.) #1

470 CHAPTER 12: Digital Audio: Providing Aural Feedback for UI Designs Using SoundPool



  1. Once you have a volumeSet volume setting variable calculated, you can
    make a SoundPool .play( ) method call.

  2. Call the .play( ) method off of your buttonSamples SoundPool object and
    then pass over parameters for the sample you want to play. These are
    denoted using the variable sound in the .triggerSample( ) method you are
    coding here, the left volume and right volume, the sample priority value, the
    number of times to play the sound (remember that zero means to play one
    time), and your pitch shifting factor, from 0.5 to 2.0 octaves, denoted using
    the variable pitch. This statement is coded using the following Java code
    shown in Figure 12-24.


buttonSamples.play( buttonSampleArray.get(sound), volumeSet, volumeSet, 0, 0, pitch );

This is the most important line of code in your .triggerSample( ) method, as everything else in the
method goes into this line of code, from the sound and pitch parameters to the volumeSet variable,
and the other lines of code that allow that variable to be calculated and established before it is
passed into (used in) the .play( ) method call.


Now you have coded everything that you need to be able to call the .triggerSample( ) method inside
of the event handling code that you have already created for your ImageButton UI elements. Let’s
do that next, so that you can hear how SoundPool will trigger your different sound effect samples for
your different ImageButton UI elements.


Figure 12-24. Call a .play( ) method off of the buttonSamples SoundPool object and pass in sound and pitch parameters

Free download pdf