O'Reilly logo

Mastering Android Game Development by Raul Portales

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required