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 ...

Get Android Game Programming: A Developer’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.