Example usage for android.media MediaCodecList getCodecInfoAt

List of usage examples for android.media MediaCodecList getCodecInfoAt

Introduction

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

Prototype

public static final MediaCodecInfo getCodecInfoAt(int index) 

Source Link

Document

Return the MediaCodecInfo object for the codec at the given index in the regular list.

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 .  com*/
        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.//from w ww . j av  a2 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;
}