Can Android play a ADTS AAC file?

2.4k views Asked by At

I use code below generated a aac audio file. And the file plays fine on my windows machine. But it cannot be played on my android device using a MediaPlayer. What should I do to make the file playable on a android device? Thanks!

    MediaRecorder recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    recorder.setAudioEncodingBitRate(16 * 44100);
    recorder.setAudioSamplingRate(44100);
    recorder.setAudioChannels(2);
    recorder.setOutputFile(mTempFile.getAbsolutePath());
1

There are 1 answers

1
VC.One On BEST ANSWER

"Can Android play a ADTS AAC file?..."

Not with default apps. Only if you code such an app. Use the MediaCodec API to manually send each of your aac frame's bytes to the decoder.

If you can handle bytes and familiar with aac frame structre, then check these as starting points :

Decoding AAC using MediaCodec API on Android

PCM -> AAC (Encoder) -> PCM(Decoder) in real-time with correct optimization

"But it cannot be played on my android device using a MediaPlayer... What should I do to make the file playable on a android device?..."

The aac data must exist inside a container format like m4a or mp4.
MediaPlayer (strangely) does not play raw aac data, yet does not expect raw mp3 to be contained.

note:
When placed inside one of the above, you will lose the ADTS header for each frame (since that information will now exist in other parts of the container's metadata).