Get supported Codec for Android device

Marcus Wolschon picture Marcus Wolschon · Aug 3, 2012 · Viewed 9.7k times · Source

Is there a way to ask an Android device what audio and video Codecs it supports for encoding?

I found devices that do not support some of the codecs listed as mandatory in http://developer.android.com/guide/appendix/media-formats.html and there seem to be devices supporting additional codec not listed there.

Answer

Jonson picture Jonson · Oct 27, 2014

That could be interesting for you:

 private static MediaCodecInfo selectCodec(String mimeType) {
     int numCodecs = MediaCodecList.getCodecCount();
     for (int i = 0; i < numCodecs; i++) {
         MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);

         if (!codecInfo.isEncoder()) {
             continue;
         }

         String[] types = codecInfo.getSupportedTypes();
         for (int j = 0; j < types.length; j++) {
             if (types[j].equalsIgnoreCase(mimeType)) {
                 return codecInfo;
             }
         }
     }
     return null;
 }

Found it here. AS you can see you get the number of installed codecs with MediaCodecList.getCodecCount();. With MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i); you get information about a specific codec out of the list. codecInfo.getName() for example tells you title/name of the codec.