Hello guys today I’d like to discuss how I got the music to play in the splash screen here. First off, create a MediaPlayer object.
MediaPlayer song = MediaPlayer.create(context, reid);
It takes in a context, in our case of Splash.this – the class is known as splash. And the “reid” is where the song is located. The song should be in the resource(res) folder. Add a new folder where you will be keeping all your sound. It should finally look like:
MediaPlayer song = MediaPlayer.create(Splash.this, R.raw.door); //the song is door.mp3
To start the song you use:
And because this was a splash screen, the song had to end when the splash screen ends or pauses. So, at the onPause() method I added:
And that will end the song. Simple as that. This probably doesn’t make any sense so hope over to the full source code and hopefully you will be enlightened more. There are more resources at: MediaPlayer | Android Devolopers.
Also I do plan on creating a music player that shall make use of all the MediaPlayer methods. I thought it will be cool.