A (175)

(Tuis.) #1
CHAPTER 12: Digital Audio: Providing Aural Feedback for UI Designs Using SoundPool 467

When you call this custom method, you will pass the SparseIntArray number of the sound you want
to use (1, 2, or 3) and the pitch you want to shift it to (1.0 for default octave, 0.5 for down an octave,
or 2.0 for up an octave) using the following format triggerSample(1, 1.0), which would play your
buttonaudio sample “as-is.”


Inside of this .triggerSample( ) method, you will write all of the Java code to set up your sample
playback, using the AudioManager class (and an AudioManager object) to access the Android
System Service, which controls the audio playback hardware for your user’s hardware device.



  1. Declare and instantiate an AudioManager object named audioControl and
    set it equal to a method call to the getSystemService( ) method called off
    of the AudioManager class and pass a Context object into it, configured for
    the AUDIO_SERVICE by using the following single line of Java code, as is
    shown in Figure 12-21:


AudioManager audioControl = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

Figure 12-20. Add a public void triggerSample( ) method with a parameter int named sound and a float named pitch

Free download pdf