获取视频的宽高和长度

android.media.MediaMetadataRetriever mmr = new android.media.MediaMetadataRetriever();

try {
    if (mUri != null) {
        HashMap headers = mHeaders;
        if (headers == null) {
            headers = new HashMap();
            headers.put("User-Agent", "Mozilla/5.0 (Linux; U; Android 4.4.2; zh-CN; MW-KW-001 Build/JRO03C) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/1.0.0.001 U4/0.8.0 Mobile Safari/533.1");
        }
        mmr.setDataSource(mUri, headers);
    } else {
        mmr.setDataSource(mFD, mOffset, mLength);
    }

    String duration = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_DURATION);
    String width = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
    String height = mmr.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);

} catch (Exception ex) {
    Log.e(TAG, "MediaMetadataRetriever exception " + ex);
} finally {
    mmr.release();
}


你可能感兴趣的:(获取视频的宽高和长度)