Streaming AAC audio with Android

Viewed 35461

As I understand it, Android will only play AAC format audio if it's encoded as MPEG-4 or 3GPP.

I'm able to play AAC audio encoded as M4A when it's local to the app, but it fails when obtaining it from a server.

The following works, as the m4a file is held locally in the res/raw directory.

MediaPlayer mp = MediaPlayer.create(this, R.raw.*file*);
mp.start();

The following doesn't work. (But does with MP3's).

Uri uri = Uri.parse("http://*example.com*/blah.m4a");
MediaPlayer mp = MediaPlayer.create(this, uri);
mp.start();

Can anyone shed any light on why it fails when the m4a audio file is not local?

Here's (some of) the error...

ERROR/PlayerDriver(542): Command PLAYER_INIT completed with an error or info UNKNOWN PVMFStatus
ERROR/MediaPlayer(769): error (200, -32)  
WARN/PlayerDriver(542): PVMFInfoErrorHandlingComplete  
DEBUG/MediaPlayer(769): create failed:  
DEBUG/MediaPlayer(769): java.io.IOException: Prepare failed.: status=0xC8  
DEBUG/MediaPlayer(769):     at android.media.MediaPlayer.prepare(Native Method)  
DEBUG/MediaPlayer(769):     at android.media.MediaPlayer.create(MediaPlayer.java:530)  
DEBUG/MediaPlayer(769):     at android.media.MediaPlayer.create(MediaPlayer.java:507)   
...

I'm targeting SDK 1.6.

5 Answers

I found that if you record the audio file on Android with the following properties, you are then able to play it on your server. It also plays well in the HTML Audio Element, however only on Firefox at the moment. This may change in the future.

Android (JAVA):

mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC);
mediaRecorder.setAudioSamplingRate(44100);
mediaRecorder.setAudioChannels(1);
mediaRecorder.setOutputFile(filePath);

HTML:

<audio id="audioMediaControl" controls src="yourfile.m4a"> Your browser does not support the audio element. </audio>

try --

1) MP.prepareAsync()

2) onPrepared() { mp.start() }

Related