How to record audio in mp4/m4a format in Android 2.3(Gingerbread)?

aac, android, android-mediarecorder, mediarecorder, mp4

Solution

Found the solution. Actually, might as well call it a bug in Android.

I did not stop the audio using `mRecorder.stop()` but had set `mRecorder.setMaxDuration(10000)`. So, the audio recorder stopped automatically and did not encode the audio to AAC or did not apply the appropriate containers, hence would not get the proper files.

The solution is simple in case you are using `mRecorder.setMaxDuration()`, implement the containing class with `MediaRecorder.OnInfoListener` and when the callback for the time out occurs call `mRecorder.stop()`

Problem

I am trying to record audio in my Android app, but I want the audio file in .mp4 format with AAC LC encoding ; playable on my desktop. So, using the following code, I tried to record, and i was able to play it back on my android. ``` mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mRecorder.setOutputFile("/mnt/sdcard/abcapp/test.mp4"); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); ``` But, when I tried to play it on my PC, I was not able to play the mp4 file. I tried it using all the media players including VLC, KMPlayer, etc. but was not able to play it. The most irritating point is that there are apps on the Play Store like "Easy Voice Recorder" which record in .mp4 and can be played back using Windows Media Player. Please help. Thanks

Original source