Android – How to record sound in Android app

androidaudioaudio-recording

I'm developing an Android application, a part of this app is a simple xylophone, what i must do is the implementation of a function, that records the xylophone sounds when the user press a button.

When a user press a button, like do, re mi, etc the sounds is played using a mp3 saved in raw folder…

1) Is it possible do this ?
2) Can someone explain how i can "capture" the sound and record it in sd card?
3) Is it possible implements "record" "play" "stop" "reproduce" function ?

Best Answer

You can record audio by using this code:

private void startRecording() {
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setOutputFile(mFileName);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

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

        mRecorder.start();
    }

I am searching for how to record audio with earphone, not from speakers please share link in the comment If anyone have Idea about it.