rmooney
rmooney

Reputation: 6229

MediaRecorder cuts off end of file

In my application, I am recording audio in m4a (AAC encoded) using MediaRecorder. All my recordings are cut short (by about half a second). For the purposes of my application, it is important that I have the entire file. Is this a bug or is there something I am missing?

Record Code:

       //set up recorder
        recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_RECOGNITION);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setAudioChannels(1);
        recorder.setAudioSamplingRate(16000);
        recorder.setOutputFile(fileName);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

        //begin recording
        recorder.prepare();
        recorder.start();

Stop Record Code:

        //stop recording
        recorder.stop();
        recorder.release();
        recorder = null;

Upvotes: 4

Views: 1891

Answers (1)

James
James

Reputation: 569

This appears to be a bug in Android's AAC based audio encoders. The only solution I have found that works is to use an AMR based audio encoder. Unfortunately, AMR_WB doesn't sound all that great for anything other than human voice.

recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);

The only other option, as near as I can tell, is to use and AudioRecord, which is much more difficult.

Upvotes: 6

Related Questions