Playing music

The other type of sound that a game contains is background music. These tracks are usually longer than the sound effects and are played in a loop. In some cases there may be more than one track, for example, if we want a music for the menu and another one for the level, or if we want several levels with different background music tracks. We will work with a single one, but it is very easy to extend it to multiple tracks.

We are going to use MediaPlayer to play the background music in our game and we are going to abstract it via SoundManager as well, providing methods to pause and resume the music when the activity is paused and resumed.

Obtaining music

As with sound effects, we need some tracks to work with. When it comes to making ...

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.