Detect supported audio encoders on Android to prevent crash “The given audio encoder 2 is not found”

孤街醉人 提交于 2019-12-10 17:19:38

问题


When an Android device does not support a mandatory audio-encoder, you get: (X=numeric index of the encoder)

E/MediaProfiles(4048): The given audio encoder X is not found A/AudioSource(4048): frameworks/base/media/libstagefright/AudioSource.cpp:58 CHECK(channels == 1 || channels == 2) failed. A/libc(4048): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1) In native code. No Exception to react to. App is just force closed.

Is there any way to query an Android >3.x device if AAC AMR-NB and AMR-WB are actually supported? Documentation ( http://developer.android.com/guide/appendix/media-formats.html ) says that these are core media formats and thus always supported. Some actual and common phones out there (of major brands) don't.

MediaCodec.createByCodecName(String name) and Get supported Codec for Android device only works with API16=Android 4.1 but the devices in question are 4.0.x . It also does not list AMR-NB and AAC.


回答1:


On your Android device, the media profiles/capabilities are stored in a config file called media_profiles.xml(on ICS/4.0).

Normally, this file is located in /etc folder on the device.

So what you could do is

  1. Connect your device to pc and pull /etc/media_profiles.xml file using adb pull command
  2. Examine the AudioEncoderCap properties. There will be multiple entries for each capbility that is advertised. for ex:

    AudioEncoderCap name="aac" enabled="true" minBitRate="8192" maxBitRate="96000" minSampleRate="8000" maxSampleRate="16000" minChannels="1" maxChannels="1"

  3. If the 'enabled' flag is set to "true" as above, then that capability should be supported by the device. If it is not supported, the 'enabled' flag will be set to "false".

AFAIK, the media codecs framework introduced on jb (4.1) read this/similar config file to expose the device capabilities to the application layer.

Hope this helps.

Thanks!



来源:https://stackoverflow.com/questions/13340227/detect-supported-audio-encoders-on-android-to-prevent-crash-the-given-audio-enc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!