package com.lgkj.webviewmoving;

import android.media.MediaMetadataRetriever;

import android.util.Log;

import java.util.HashMap;

public class VideoUtils {

private VideoInformations videoInformations;

public VideoUtils(VideoInformations videoInformations) {

this.videoInformations = videoInformations;

}

//获取视频的宽高,和时长

private void getVideoWidthAndHeightAndVideoTimes(String videoUrl) {

final MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();

mediaMetadataRetriever.setDataSource(videoUrl, new HashMap());

new Thread() {

@Override

public void run() {

float videoTimes = 0;

float videoWidth = 0;

float videoHeight = 0;

super.run();

try {

videoTimes = Float.parseFloat(mediaMetadataRetriever.extractMetadata(android.media.MediaMetadataRetriever.METADATA_KEY_DURATION));

videoWidth = Float.parseFloat(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));

videoHeight = Float.parseFloat(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));

} catch (Exception e) {

videoTimes = 0;

videoWidth = 0;

videoHeight = 0;

} finally {

Log.i("zzm", "视频的宽: " + videoWidth);

Log.i("zzm", "视频的高: " + videoHeight);

Log.i("zzm", "视频的长度: " + videoTimes);

mediaMetadataRetriever.release();

videoInformations.dealWithVideoInformation(videoWidth, videoHeight, videoTimes);

}

}

}.start();

}

interface VideoInformations {

void dealWithVideoInformation(float w, float h, float vt);

}

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐