5

I am decoding audio using MediaExtractor, MediaCodec, and AudioTrack. I am configuring the AudioTrack using the MediaFormat returned by MediaCodec.getOutputFormat() after receiving MediaCodec.INFO_OUTPUT_FORMAT_CHANGED from the MediaCodec. On some devices, this results in speeded up audio, while the MediaFormat returned by the MediaExtractor works correctly. (On other devices, the reverse is true.)

Here are some details:

  • The audio files in question are largely 22050 Hz mono MP3s.
  • The devices where playback is too fast include the Prestigio PMP3007C3G, ASUS MeMO Pad HD 7 (ME173X), Lenovo A5500-H (A5500-H), and some Wiko devices.
  • I unfortunately don't know the parameters of the returned MediaFormat, as I don't have access to the devices, but I assume that it returns stereo for mono, or 44100 Hz for 22050 Hz, without actually resampling the files.

Any help would be appreciated. Thanks!

Tad
  • 4,668
  • 34
  • 35
  • 1
    I don't have a good fix suggestion to make; it sounds to me like these devices' decoders are buggy - your code is doing the correct thing right now. (The `MediaFormat` that `MediaCodec` returns should be more authoritative than the one from `MediaExtractor`.) Since the returned changed parameters (especially for stereo output from mono input) seem legit, it's pretty hard to make some sort of heuristic to try to guess whether it is wrong. If you can pinpoint this behaviour to one (or a few) decoder names or chipsets, you might be able to try to detect it and work around it. – mstorsjo Jun 11 '15 at 18:40
  • Thanks - that seems to reflect the situation pretty well. Android MediaPlayer seems to work correctly on those devices, though, so I'll keep poking around and see if there is something else I can find. – Tad Jun 12 '15 at 06:28
  • 2
    Did you find reason why audio plays faster on some devices? – Nik Aug 22 '15 at 16:53
  • Perhaps following from [link](https://software.intel.com/sites/landingpage/mmsf/documentation/mmsfexample11_2java_2android_2intel_2sample_2mmsf_2MediaPlayer_8java_source.html) might help:`int sampleRate = AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC);` `audioTrack.setPlaybackRate(sampleRate);` – beyeriii Feb 23 '19 at 07:24

0 Answers0