Android definitely has an MP3 encoder.
As I replied to https://stackoverflow.com/a/312960/409 , all you have to do is:
MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setOutputFile(Environment.getExternalStorageDirectory() .getAbsolutePath() + "/myrecording.mp3"); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); recorder.prepare(); recorder.start();
The important part here is setOuputFormat and setAudioEncoder . MediaRecorder records playable mp3s if you use MediaRecorder.OutputFormat.MPEG_4 and MediaRecorder.AudioEncoder.AAC together.
The funny thing is that this solution was the result of my experiments with what works, and I have no idea why this works. I was hoping someone could shed some light on this in the comments.
EDIT
As @JohnSmith and several others pointed out in the comments, this does not encode MP3 audio, and Android does not have a built-in MP3 encoder.
The reason this solution works is because MediaPlayer recognizes the encoding as AAC before the start of the track (regardless of the file extension). Thus, although the mime file type of the output file is audio / mp4, the encoding is certainly AAC.
Advait S
source share