The Wayback Machine - https://web.archive.org/web/20240614203715/https://www.geeksforgeeks.org/how-to-add-audio-files-to-android-app-in-android-studio/
Open In App

How to Add Audio Files to Android App in Android Studio?

Last Updated : 18 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The audio file format is a file format for saving digital audio data on a computer system and all are aware of audio files. So in this article, we are going to discuss how can we add audio files to the android app. There are three major groups of audio file formats:

Format Name

Description

Examples

Uncompressed audio formats Uncompressed audio formats are also known as raw audio format. RAW Audio format or just RAW Audio is an audio file format for saving uncompressed audio in raw form. Comparable to WAV or AIFF in size, the RAW Audio file does not include any header information. WAV (Waveform Audio File Format), AIFF (Audio Interchange File Format), etc.
Formats with lossless compression A lossless compressed audio format saves data in a smaller space without wasting any information. The original, uncompressed data can be recreated from the compressed version. FLAC, Monkey’s Audio WavePack, TTA
Formats with lossy compression The lossy audio format allows even greater reductions in file size by eliminating some of the audio information and simplifying the data. Opus, MP3, Vorbis, Musepack, AAC, ATRAC

Note: Android supports the following audio format

  • MP3
  • MIDI
  • Opus
  • Vorbis
  • PCM/WAVE
  • FLAC
  • AMR-WB
  • AMR-NB etc.

Step by Step Implementation

Step 1: Open your android studio go to the app > res > right-click > New > Android Resource Directory as shown in the below image. 

Step 2: Then a pop-up screen will arise like below. Here in Resource type choose raw.

Step 3: After choosing the raw from the dropdown menu click on the OK button and keep all the things as it is.

Step 4: Now you can see the raw folder has been created and you can find the folded in the app > res > raw as shown in the below image. 

Step 5: After creating the raw folder successfully go to your own system and copy the required audio files as we do normally. Now again come back to the android studio and right-click on the raw folder. Then click on the Paste button as shown in the below image.

Step 6: Here on this screen you can rename your audio file name as your requirement. And click on the Refactor button. And you are done.

Now go to the app > res > raw and you can find your audio file as shown in the below figure.

Now open the Java File of the desired activity, here we are adding audio in the MainActivity.java file and add this following code in the MainActivity.java file.

Java




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



Similar Reads

How to Add Firebase Analytics to Android App in Android Studio?
Analytics is one of the important tools that developers should definitely used while building their applications. It is very helpful to target your apps for various audience ranges and to track on which screen the users are spending a long time. So it is one of the important features which one should not miss adding while building any Android Appli
4 min read
How to fix "Android Studio doesn't see device" in Android Studio?
In Android Studio, sometimes the list of devices and emulators doesn't list your physical device when you try to plug it in. Or you may have faced a situation when you plugged the phone in for the first time, no dialog appeared asking if you trust the computer. But the laptop is already allowed to connect to the mobile device. However, the button R
4 min read
How to Fix "Android studio logcat nothing to show" in Android Studio?
Logcat Window is the place where various messages can be printed when an application runs. Suppose, you are running your application and the program crashes, unfortunately. Then, Logcat Window is going to help you to debug the output by collecting and viewing all the messages that your emulator throws. So, this is a very useful component for the ap
2 min read
Different Ways to Analyze APK Size of an Android App in Android Studio
APK size is one of the most important when we are uploading our app to Google Play. APK size must be considered to be as small as possible so users can visit our app and download our app without wasting so much data. In this article, we will take a look at How we can analyze our APK in Android Studio to check the APK size. Android Studio itself pro
3 min read
How to Build a Number Shapes Android App in Android Studio?
Android is a vast field to learn and explore and to make this learning journey more interesting and productive we should keep trying new problems with new logic. So, today we are going to develop an application in android studio which tells us about Numbers that have shapes. We will be covering two types of numbers i.e. triangular and square. So, f
4 min read
How to Build a Decimal to Binary Converter Android App in Android Studio?
This app will convert a Decimal Number into a Binary Number. Some people may also have written a java program to convert a Decimal Number into Binary Number, but while making an app let's see how to do that. Brief Go through We will start by creating a new project with an Empty Activity. After creating a project, we would add the drawable resource
5 min read
How to Build Binary to Decimal Converter Android App in Android Studio?
This app will convert a Binary Number into a Decimal Number. Some people may also have written a java program to convert a Binary Number into a Decimal Number, but while making an app let's see how to do that. Brief Go Through We will start by creating a new project with an Empty Activity. After creating a project, we would add the drawable resourc
5 min read
How to Use Stack Overflow to Fix Errors During Android App Development in Android Studio?
Stack Overflow, the life savior of developers, feels like Stack Overflow is built for the developers, by the developers, of the developers. According to Wikipedia: "Stack Overflow is a question-and-answer site for professional and enthusiast programmers". So being a developer or programmer can you imagine your life without Stack Overflow…. ? Most p
4 min read
How to Build Decimal to Hexadecimal Converter Android App in Android Studio?
In this article, we would be learning how to make a Decimal to Hexadecimal Converter App in Java in Android Studio. This app would take an input of a Decimal number, convert it into a Hexadecimal number and then show the output. So let's go through the brief go through of how we would be making the app. Brief Go through We will begin by first creat
5 min read
How to Make a Scientific Calculator Android App using Android Studio?
The calculator is the app that is present on every android device. This app comes pre-installed or we can also install another application from Play Store. It is one of the most used applications for college students for making any calculations. In this article, we will take a look at building a simple scientific calculator app in Android using Kot
13 min read
Article Tags :