Example usage for android.media MediaCodecList getCodecCount

List of usage examples for android.media MediaCodecList getCodecCount

Introduction

In this page you can find the example usage for android.media MediaCodecList getCodecCount.

Prototype

public static final int getCodecCount() 

Source Link

Document

Count the number of available (regular) codecs.

Usage

From source file:Main.java

public 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;
        }/*from   w ww  .  j  a  v  a 2 s .c om*/
        String[] types = codecInfo.getSupportedTypes();
        for (int j = 0; j < types.length; j++) {
            if (types[j].equalsIgnoreCase(mimeType)) {
                return codecInfo;
            }
        }
    }
    return null;
}

From source file:Main.java

/**
 * Returns the first codec capable of encoding the specified MIME type, or null if no
 * match was found./*w ww  .j a v  a  2 s . c o m*/
 *
 * @param mimeType String
 * @return MediaCodecInfo
 */
public 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 (String type : types) {
            if (type.equalsIgnoreCase(mimeType)) {
                return codecInfo;
            }
        }
    }
    return null;
}