Android – Simple Audio Recorder Example | NEW 2017

Android audio recorder tutorial 2017 no deprecation

Get the full code of android audio recorder. Android voice recorder tutorial is another simple program for beginner. It is also known as media recorder part of audio recorder. Below is full code.

android audio recorder

Android audio recorder MainActivity source code

Change package name with your own package name.

package utube.attraction.voicerecorder;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.io.IOException;

public class MainActivit extends Activity {

Button play,stop,record;
private MediaRecorder mr;
private String outputFile = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

play = (Button)findViewById(R.id.button3);
stop = (Button)findViewById(R.id.button2);
record = (Button)findViewById(R.id.button);

stop.setEnabled(false);
play.setEnabled(false);
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + “/recordingone.3gp”;

mr = new MediaRecorder();
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mr.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mr.setOutputFile(outputFile);

record.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
mr.prepare();
mr.start();
}
catch (IllegalStateException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
record.setEnabled(false);
stop.setEnabled(true);
Toast.makeText(getApplicationContext(), “Recording started”, Toast.LENGTH_LONG).show();
}
});

stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mr.stop();
mr.release();
mr = null;
stop.setEnabled(false);
play.setEnabled(true);
Toast.makeText(getApplicationContext(), “Audio recorded successfully”,Toast.LENGTH_LONG).show();
}
});

play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) throws IllegalArgumentException,SecurityException,IllegalStateException {
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(outputFile);
}
catch (IOException e) {
e.printStackTrace();
}
try {
mp.prepare();
}
catch (IOException e) {
e.printStackTrace();
}
mp.start();
Toast.makeText(getApplicationContext(), “Playing audio”, Toast.LENGTH_LONG).show();
}
});
}
}

Android voice recorder tutorial 2017 AndroidManifest.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”utube.attraction.voicerecorder”>

<uses-permission android:name=”android.permission.STORAGE” />
<uses-permission android:name=”android.permission.RECORD_AUDIO” />
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” />

<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:supportsRtl=”true”
android:theme=”@android:style/Theme.NoDisplay”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>

<activity android:name=”.SaveAudio”
android:theme=”@style/AppTheme”></activity>

</application>

</manifest>

Android audio capture activity_main.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:app=”http://schemas.android.com/apk/res-auto”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
tools:context=”your package name.MainActivity”>

<Button
android:id=”@+id/button”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentStart=”true”
android:layout_alignParentTop=”true”
android:layout_marginStart=”32dp”
android:layout_marginTop=”80dp”
android:text=”Record” />

<Button
android:id=”@+id/button2″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignEnd=”@+id/button”
android:layout_below=”@+id/button”
android:layout_marginTop=”50dp”
android:text=”STOP” />

<Button
android:id=”@+id/button3″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignEnd=”@+id/button2″
android:layout_below=”@+id/button2″
android:layout_marginTop=”58dp”
android:text=”PLAY” />
</RelativeLayout>

Get more android tutorial from our YouTube channel ATTRACTION.
Visit our NextGenEarn Blog for more new online money making ways.

Android funny voice changer source code

Android change voice bit rate and sample rate watch this video get code. Complete source code.

Add a Comment

Your email address will not be published. Required fields are marked *