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());
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
The
aac
data must exist inside a container format likem4a
ormp4
.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).