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

0

Last Updated : 18 Feb, 2021

The audio file format is a file format for saving digital audio information on a pc system and all are conscious of audio information. So on this article, we’re going to focus on how can we add audio information to the android app. There are three main teams of audio file codecs:

Format Name

Description

Examples

Uncompressed audio codecs Uncompressed audio codecs are also referred to as uncooked audio format. RAW Audio format or simply RAW Audio is an audio file format for saving uncompressed audio in uncooked type. Comparable to WAV or AIFF in dimension, the RAW Audio file doesn’t embrace any header info. WAV (Waveform Audio File Format), AIFF (Audio Interchange File Format), and so on.
Formats with lossless compression A lossless compressed audio format saves information in a smaller area with out losing any info. The authentic, uncompressed information may be recreated from the compressed model. FLAC, Monkey’s Audio WavePack, TTA
Formats with lossy compression The lossy audio format permits even larger reductions in file dimension by eliminating among the audio info and simplifying the info. Opus, MP3, Vorbis, Musepack, AAC, ATRAC

Note: Android helps the next audio format

  • MP3
  • MIDI
  • Opus
  • Vorbis
  • PCM/WAVE
  • FLAC
  • AMR-WB
  • AMR-NB and so on.

Step by Step Implementation

Step 1: Open your android studio go to the app > res > right-click > New > Android Resource Directory as proven within the beneath picture. 

Step 2: Then a pop-up display screen will come up like beneath. Here in Resource kind select uncooked.

Step 3: After selecting the uncooked from the dropdown menu click on on the OK button and maintain all of the issues as it’s.

Step 4: Now you may see the uncooked folder has been created and you will discover the folded within the app > res > uncooked as proven within the beneath picture. 

Step 5: After creating the uncooked folder efficiently go to your individual system and copy the required audio information as we do usually. Now once more come again to the android studio and right-click on the uncooked folder. Then click on on the Paste button as proven within the beneath picture.

Step 6: Here on this display screen you may rename your audio file title as your requirement. And click on on the Refactor button. And you’re performed.

Now go to the app > res > uncooked and you will discover your audio file as proven within the beneath determine.

Now open the Java File of the specified exercise, right here we’re including audio within the MainActivity.java file and add this following code within the MainActivity.java file.

Java

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

music.begin();

News

Improve

Leave A Reply

Your email address will not be published.