Android examples for android.media:Audio
create Media Recorder to record audio
import java.io.File; import java.io.IOException; import android.media.MediaRecorder; public class Main { private static File tempAudioFileForRecorder = null; private final static String RECORDER_PLAYBACKFILE_PATH_PREFIX = "recordertemp"; /**/*from w w w. ja v a 2s . com*/ * create MediaRecorder to record audio * * @return MediaRecorder */ public static MediaRecorder createMediaRecorder() { MediaRecorder recorder = null; try { recorder = new MediaRecorder(); tempAudioFileForRecorder = File.createTempFile(RECORDER_PLAYBACKFILE_PATH_PREFIX, "temp"); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); // recorder.setMaxDuration(500); recorder.setAudioChannels(1); recorder.setAudioSamplingRate(8000); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setOutputFile(tempAudioFileForRecorder.getAbsolutePath()); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.prepare(); } catch (IOException e) { e.printStackTrace(); } return recorder; } }