Creating 2D Car Racing Game in Android: 6. Adding Music into the Game

Well….! This is the last and final part of this game tutorial. In this part you will learn how to add background music into game using Service class.
So let’s see how to add music….!

Topics Covered

Importing Music File into Project

Before import the music file into Project, create a folder named “raw” inside “res” folder of the Project. Now drag the music file into raw folder. i.e. bgmusic.ogg

Creating 2D Car Racing Game In Android

Creating Background Music Service Class

Create the BGMusic class and extend it by Service class.

Now implement the logic to play music.

Now add the service node under application node in AndroidMenifest.xml

Running Music using Thread

Now open and add following code snippets inside onCreate() function.

Run and test the app to see the result.

Download Complete Source
I hope now you got the basic idea how we can create simple game using OpenGL.

13 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *