July 2015
Beginner to intermediate
600 pages
18h 59m
English
The next thing to do with your SoundPool is to load it up with sounds. The main benefit of using a SoundPool over some other methods of playing audio is that SoundPool is responsive: when you tell it to play a sound, it will play the sound immediately, with no lag.
The trade-off for that is that you have to load sounds into your SoundPool before you play them. Each sound you load will get its own integer ID. So go ahead and add a mSoundId field to Sound and a generated getter and setter to keep track of this.
Listing 19.2 Adding sound ID field (Sound.java)
public class Sound {
private String mAssetPath;
private String mName;
private Integer mSoundId;
...
public String getName() {
return mName;
}
public Integer ...Read now
Unlock full access