How To Add Audio To App In Android Studio

Adding audio clip to android application is a simple task as it also add some further functionality. Here is a step by step on how to play music when App will start.


Adding Audio to app in Android Studio:

Step 1: Open the android studio with the project in which you want to add-on audio clip/media file.
Step 2: Create a raw folder.
Step 3: Add media file to raw folder by simply copy and paste that to raw folder.
adding-media-in-android-studio
Step 4: Here we added a media file “ring.mp3” . Now open the Java File of desired activity, here we are adding audio in MainActivity.
Step 5: Further add this code

MediaPlayer ring= MediaPlayer.create(MainActivity.this,R.raw.ring);
        ring.start();

Step 6: Now run the App and your music will play when App will start.

DOWNLOAD THIS
FREE eBook!

This free eBook will help you master the learning of Android App Development in Android Studio!

19 thoughts on “How To Add Audio To App In Android Studio”

  1. MediaPlayer sing= MediaPlayer.create(MainActivity.this,R.raw.ring);
    sing.start();
    raw cannot resolve

  2. Hello, I need to add additional options for sounds to my project. I’m using the android-Repeating Alarm from github.com. I’m just not sure how to go about it.

    Thanks.

  3. Hi,pls i need your help.i created a setting activity where i have a switch which i intend to control my app background sound/music ,but i cant get the switch to control my sound.

  4. Hi, I did exactly what is written here but android studio says : it cannot resolve the work START which you have written on the second line : ring.start();

    1. You have to put all of this in a function. And that function I’ve put on a ‘onClick’-event. It works just fine!
      But i would like to play it when the activity starts. That’s my next step.

  5. I already add raw folder to my project with audio but when I build the program it shows error that cannot find symbol variable raw please help me