I have a system decoding MP3 audio with MediaExtractor
, converting it with MediaCodec
and playing it with AudioTrack
. On most devices it works fine, but on the Samsung Galaxy S3 and Samsung Galaxy Tab, some users report extremely slow audio playback. I can't reproduce it on an emulator or physical devices.
Asked
Active
Viewed 564 times
1

Tad
- 4,668
- 34
- 35
-
http://stackoverflow.com/questions/30788496/android-audio-too-fast-on-some-devices-with-mediacodec-and-audiotrack is a continuation of this issue? – fadden Jun 12 '15 at 16:55
-
It's a related, but different issue. This one relates to dealing with hardware that does the right thing - that one relates to hardware that does the wrong thing. – Tad Jun 14 '15 at 21:50
1 Answers
2
After much trouble, it turns out that the issue was with my use of MediaFormat
. On some devices, the MediaFormat returned by MediaCodec
is not the same as the one returned by MediaExtractor
. Frame rates, etc., may change. Instead of instantiating AudioTrack
with the MediaFormat returned by MediaExtractor, it was necessary to wait until decoding began. At that point, MediaCodec.dequeueOutputBuffer()
will return MediaCodec.INFO_OUTPUT_FORMAT_CHANGED
. MediaCodec.getOutputFormat()
can then be used return the correct MediaFormat with which to initialize the AudioTrack. Hope this helps someone.

Tad
- 4,668
- 34
- 35
-
1Can you paste an example of "early" and "late" MediaFormats into the answer? I'm curious what the difference is. – fadden Jun 08 '15 at 20:11
-
I actually don't have an affected device, so I don't know the details. Since the voice was slow, it must be a faster bit rate, mono to stereo, or possibly more bits per sample. A few people have reported, however, that playback is now too fast. I'll post back here when I figure out what is going on with that. – Tad Jun 11 '15 at 06:48
-
@fadden: I've seen some cases of AAC decoders decode mono input data into stereo at least. (This is a common phenomenon with many decoders when given HE-AACv1 data actually, but in my case it happened with either plain AAC-LC, or AAC-LD.) – mstorsjo Jun 12 '15 at 10:41