Chapter 6. Sound FX and Music
A game feels incomplete without sound. In this chapter we will explore the different options for playing sound effects and music in Android, we will build a SoundManager class to handle them, and we will see how it interacts with the GameEngine.
For sound effects we will use SoundPool, which has been specifically designed for playing small sounds by preloading them in memory. To trigger the sound effects, we will introduce the concept of GameEvent and learn how they are propagated through the GameEngine.
In the case of background music, we will use MediaPlayer directly since long tracks do not work well with SoundPool, and MediaPlayer is the generic solution for playing all types of media files.
Finally, we will add ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access