2012-08-03 100 views

回答

4

有没有办法问一个Android设备它支持哪些音频和视频编码解码器?

我真的希望有,但至少没有通过ICS。

果冻豆提供MediaCodec类。虽然它没有“给我一个支持的编解码器列表”,但它确实有createEncoderByType(),您传递的是MIME类型。据推测,如果您所需的MIME类型不受支持,则会抛出RuntimeException或返回null。我不能保证只是因为MediaCodec报告有一个编码器可以使用,例如MediaRecorder

+1

而MediaCodec有一组来自MediaRecorder的编解码器常量。 – 2012-09-24 07:23:15

6

这可能是对你有意思:

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; 
} 

发现here。正如您所看到的,您可以通过MediaCodecList.getCodecCount();获得已安装的编解码器数量。使用MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);您可以从列表中获得有关特定编解码器的信息。例如会告诉您编解码器的标题/名称。