Android AudioTrack extremely slow on some devices

625 views Asked by At

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.

1

There are 1 answers

3
Tad On BEST ANSWER

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.