I am developing a game application in android. I have designed all the views and implemented all the functionality. Now in the last screen I have to play sounds in android. Can anybody tell me how to pursue with it?
Open your Android Studio and create a new project. Create a new folder named "raw" in your Android project's "res" folder and place your audio file inside the "raw" folder. You can see the audio is now successfully added into your Android Studio project by viewing the "raw" subfolder under "res" folder.
One of the most important components of the media framework is the MediaPlayer class. An object of this class can fetch, decode, and play both audio and video with minimal setup.
MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.AudioFile1);
mp.start();
And then you get all the start/stop/reset/pause/release methods from mp.
Just place the sound file in /res/raw
(after creating the folder) and then use MediaPlayer to init, start and then stop playing the sound. MediaPlayer documentation can be found here.
HTH,
Sriram.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With