How to record a audio in Android and save it in Da

2019-05-29 07:32发布

Hi I am making an Android app for recording a audio for 5-10 sec and store that in Database. For audio recording i follow this http://xhampa.pastebin.com/Yr2hie6q

But it is not working properly. What to do ? I can not record the Audio on my G1 mobile. Any suggestion welcome.

1条回答
祖国的老花朵
2楼-- · 2019-05-29 08:07

For your audio recording, try this code:

MediaRecorder recorder;

public void startRecording() throws IOException 
{
SimpleDateFormat timeStampFormat = new SimpleDateFormat(
        "yyyy-MM-dd-HH.mm.ss");
String fileName = "audio_" + timeStampFormat.format(new Date())
        + ".mp4";
recorder = new MediaRecorder();  
recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
recorder.setOutputFile("/sdcard/"+fileName);
recorder.prepare(); 
recorder.start();
}

protected void stopRecording() {
recorder.stop();
recorder.release();
}

You can find your file on your sdcard.

查看更多
登录 后发表回答