Record .m4a file Android

enfix picture enfix · Sep 27, 2012 · Viewed 9.7k times · Source

How can i record M4A audio file with MediaRecorder in Android 2.2 ?
What output format, encoder and sampling rate i need to set ?

I need to record it from microphone and save it in SDCARD

UPDATE

I tried this code, but the result doesn't valid (not play in browser for example):

recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // error here ?!?
recorder.setAudioSamplingRate(96000); // what value ?

Answer

BinCodinLong picture BinCodinLong · Mar 13, 2015

These codes work to produce an m4a file:

    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC);

or

    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

with

    mRecorder.setAudioChannels(1);
    mRecorder.setAudioSamplingRate(44100);
    mRecorder.setAudioEncodingBitRate(96000);
    mRecorder.setOutputFile(absFilePath);// must have an .m4a extension