0

In my android application, I want to record my voice as an MP3 file. But Android's Media Recorder (class that supports audio recording) does not seem to support MP3 format. It seems to allow only 3gp and mpeg4 file formats.

recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG4);

Can anyone help me out or give me a code ?

Oak Bytes
  • 4,649
  • 4
  • 36
  • 53

3 Answers3

1

Mp3 encoder is not available in android, But mp3 can be encoded using Libav/FFMPeg with mp3 LAME and you can find example code here

Mohit
  • 634
  • 5
  • 15
0

Use this code this is work for me:

MediaRecorder   recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
/*  recorder.setAudioEncodingBitRate(32);
recorder.setAudioSamplingRate(44100);*/
recorder.setOutputFile(file.getPath());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
Ori Lentz
  • 3,668
  • 6
  • 22
  • 28
-2

MP3 is officially supported by android now :

http://developer.android.com/guide/appendix/media-formats.html

Core Media Formats:


Format / Codec || Details || Supported File Type(s) / Container Formats


MP3 || Mono/Stereo 8-320Kbps constant (CBR) or variable bit-rate (VBR) || MP3 (.mp3)Formats


enter image description here

You can use it as :

mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

and save the file with suffix ".mp3"

Sachin Tyagi
  • 1,257
  • 15
  • 21
  • This is just wrong. MP3 its not supported as encoder (recording) as you can see with the little dot in your own picture (missing the table titles). What matters is the AudioEncoder. The OutputFormat and the extension are unrelated; you can name an audio file .jpg if you please to. – GuillermoMP Jan 10 '17 at 12:18