-1

Im creating an application in which I want to integrate the audio recording feature and the output file must me in the .mp3 format.. Please provide me some good tutorial through from where I can learn..

Thanks in advance...

Abhishek Dhiman
  • 1,631
  • 6
  • 25
  • 38

3 Answers3

1

try the following too:

import java.io.File;
import java.io.IOException;

import android.media.MediaRecorder;
import android.os.Environment;

public class AudioRecorder {

    final MediaRecorder recorder = new MediaRecorder();
    final String path;

    public AudioRecorder(String path) {
        this.path = sanitizePath(path);
    }

    private String sanitizePath(String path) {
        if (!path.startsWith("/")) {
            path = "/" + path;
        }
        if (!path.contains(".")) {
            path += ".3gp";
        }
        return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
    }

    public void start() throws IOException {
        String state = android.os.Environment.getExternalStorageState();
        if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
            throw new IOException("SD Card is not mounted.  It is " + state + ".");
        }

        File directory = new File(path).getParentFile();
        if (!directory.exists() && !directory.mkdirs()) {
            throw new IOException("Path to file could not be created.");
        }

        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setOutputFile(path);
        recorder.prepare();
        recorder.start();
    }

    public void stop() throws IOException {
        recorder.stop();
        recorder.release();
    }
}
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
G M Ramesh
  • 3,420
  • 9
  • 37
  • 53
0

try this Android Audio Record & Audio Record using MediaRecord Android API Tutorial

Ben McCann
  • 18,548
  • 25
  • 83
  • 101
Rahul Baradia
  • 11,802
  • 17
  • 73
  • 121
0

This is the simple code to do this.

    MediaRecorder mediarecorder = new MediaRecorder();
    mediarecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediarecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mediarecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    mediarecorder.setOutputFile("/sdcard/myv.mp3");
    try {
        mediarecorder.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mediarecorder.start();
jay
  • 292
  • 1
  • 11