1、先导包
<dependency><groupId>ws.schild</groupId><artifactId>jave-all-deps</artifactId><version>2.6.0</version>
</dependency>
2、获取时长
@Testpublic void test01() {long time = 0;try {String url = "http://xxxx.mp4";MultimediaObject media = new MultimediaObject(new URL(url));MultimediaInfo info = media.getInfo();// 时长,毫秒级long duration = info.getDuration();// 毫秒级时长转化为秒BigDecimal bigDecimal1 = new BigDecimal(duration);BigDecimal bigDecimal2 = new BigDecimal(1000);// 四舍五入,只保留整数time = bigDecimal1.divide(bigDecimal2, 0, RoundingMode.HALF_UP).longValue();} catch (Exception e) {e.getMessage();}System.out.println("时长:" + time);}