Reputation: 4784
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.
Upvotes: 1
Views: 612
Reputation: 4784
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.
Upvotes: 2