28 May

Android – Audio Recorder

Kita dapat membuat recorder di dalam Android dengan cara:

Pertama tambahkan Permission

<uses-permission android:name="android.permission.RECORD_AUDIO“ />

Kedua, buat objek media recorder

final MediaRecorder recorder = new MediaRecorder();

Ketiga, Method start record

public void start() throws IOException { 
	String state = android.os.Environment.getExternalStorageState(); if(!state.equals(android.os.Environment.MEDIA_MOUNTED)) { 
		throw new IOException("SD Card is not mounted. It is " + state + "."); 
	} 
	
     File directory = new File(path).getParentFile(); 
	if (!directory.exists() && !directory.mkdirs()) { 
		throw new IOException("Path to file could not be created."); 
	} 
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); 
	recorder.prepare(); 
	recorder.start(); 
}

Keempat, Method stop record

public void stop() throws IOException { 
	recorder.stop(); 
	recorder.release(); 
}

One thought on “Android – Audio Recorder

  1. mau tanya nih bang..
    saya kn punya aplikasi piano android..
    ini aplikasi standar bgt..
    tp saya pgn dtambah record buat ngrekam bunyi yg dimainin ddlm ny..
    tu gmn cara ny..
    soalny sya coba2 gak jd..
    mohon bntu yah..
    makasih sblm ny..

Leave a Reply

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