项目中获取视频时长,需要调用腾讯云SDK
import com.qcloud.Module.Vod;
import com.qcloud.QcloudApiModuleCenter;
private String getVideoTime(Integer fileId){
TreeMap<String, Object> config = new TreeMap<>();
// 点播服务id
config.put("SecretId", secretId);
// 点播服务key
config.put("SecretKey", secretKey);
config.put("RequestMethod", "GET");
config.put("DefaultRegion", "bj");
QcloudApiModuleCenter module = new QcloudApiModuleCenter(new Vod(), config);
TreeMap<String, Object> params = new TreeMap<>();
params.put("fileId",fileId);
// 只请求基础信息
params.put("infoFilter.0","basicInfo");
String result = null;
// Integer duration = 0;
try {
result = module.call("GetVideoInfo",params);
//获取视频时长
// Map<String,Object> map = JSON.parseObject(result, Map.class);
// duration = (Integer) map.get("duration");
}catch (Exception e){
e.printStackTrace();
}
return result;
}
腾讯云SDK依赖
<!-- qcloud-java-sdk-->
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>qcloud-java-sdk</artifactId>
<version>2.0.1</version>
</dependency>