Android系统。如何通过音频流录制麦克风?

时间:2016-09-02 12:18:48

标签: android audio microphone mediarecorder

在我的应用程序播放音乐时,用户应该在此时说到麦克风。你能告诉我怎么做一个唱片吗?音乐和麦克风的顶部路径。我查看了MediaRecorder,但在我看来,没有合适的录制源。

1 个答案:

答案 0 :(得分:0)

通过麦克风进行录制

通过麦克风开始和停止录制....

开始录制

static MediaRecorder recorder = new MediaRecorder(); 
static String path, filename, time;
static int duration;
     public void startRecording() { 
        try {  
            recorder = new MediaRecorder();  
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);  
            recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);    
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);  
            System.currentTimeMillis();
            filename = ListenCallState.number + "_" + time + ".amr";
            File f = new File(getBaseURL());
            f.mkdirs();

            path = getBaseURL() + filename;
            recorder.setOutputFile(path);
            recorder.prepare();
            recorder.start();

        } catch (Exception {
        }
    }

停止录制

public static void stopRecording() {
        recorder.stop();
        recorder.release();
        try {
            MediaPlayer p = new MediaPlayer();
            p.setDataSource(path);
            p.prepare();
            duration = p.getDuration();
        } catch (Exception e) {
        }
 }