How to record a audio in Android and save it in Database?

给你一囗甜甜゛ 提交于 2019-12-08 06:49:27

问题


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:


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.



来源:https://stackoverflow.com/questions/4430794/how-to-record-a-audio-in-android-and-save-it-in-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!