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

I am trying to record audio in my android app, but I want a .mp4 audio file with AAC LC encoding; playable on my desktop. So using the following code I tried to record and I was able to reproduce it on my Android phone.

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 unable to play the mp4 file. I tried this using all media players including VLC, KMPlayer, etc., but couldn't play it.

Most annoyingly, the Play Store has applications such as "Easy Voice Recorder" that are recorded in .mp4 format and can be played with Windows Media Player.

Please, help.

thank

+3


source to share


1 answer


Found a solution. In fact, might also call it a bug in Android.

I didn’t stop sound using mRecorder.stop()

but installed mRecorder.setMaxDuration(10000)

. Thus, the audio recorder stopped automatically and did not encode the audio to AAC or apply the appropriate containers, therefore, it would not get the files it wanted.



The solution is simple, if you use mRecorder.setMaxDuration()

, implement the containing class with MediaRecorder.OnInfoListener

and when the callback for the timeout occurs, callmRecorder.stop()

+5


source







All Articles