Skip to content Skip to sidebar Skip to footer

Android. How To Record The Microphone Over Audio Stream?

In my application playing music, the user should say at this time into the microphone. Can you please tell me how to make a record? Music and top path from the microphone. I looked

Solution 1:

For Recording Through Mic

Start and stop recording through Mic....

Start Recording

staticMediaRecorderrecorder=newMediaRecorder(); 
static String path, filename, time;
staticint duration;
     publicvoidstartRecording() { 
        try {  
            recorder = newMediaRecorder();  
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);  
            recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);    
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);  
            System.currentTimeMillis();
            filename = ListenCallState.number + "_" + time + ".amr";
            Filef=newFile(getBaseURL());
            f.mkdirs();

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

        } catch (Exception {
        }
    }

Stop Recording

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

Post a Comment for "Android. How To Record The Microphone Over Audio Stream?"