Android: 录音

Android录音

/**
 * 开始录音
 */
private void startRecording() {
    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setOutputFile(getAudioFilePath());
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

    try {
        mRecorder.prepare();
    } catch (IOException e) {
        Log.e("Audio", "prepare() failed");
    }

    mRecorder.start();
}

/**
 * 停止录音
 */
private void stopRecording() {
    mRecorder.stop();
    mRecorder.release();
    mRecorder = null;
}

/**
 * 获取录音文件路径
 * @return
 */
public String getAudioFilePath() {
    String mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
    mFileName += "/temp_audio.3gp";
    return mFileName;
}
posted @ 2015-06-29 14:06  GreatK  阅读(189)  评论(0编辑  收藏  举报