获取视频播放长度
1、导入依赖 (jave-1.0.2.jar)
- 需要先下载到本地,然后引入到项目(下载地址:http://www.sauronsoftware.it/projects/jave/jave-1.0.2.zip)
-
然后找到下载好的包添加进去
-
最好是在当前项目下建一个lib文件夹(/src/main/resources/lib/)
- 在pem文件引入依赖
<dependency> <groupId>it.sauronsoftware</groupId> <artifactId>jave</artifactId> <version>1.0.2</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/lib/jave-1.0.2.jar</systemPath> </dependency>
2、这是工具类,直接引用
public static Map<String,Object> ReadVideoTime(String filePath) { Map<String,Object> resultMap=new HashMap<>(); File source = new File(filePath); Encoder encoder = new Encoder(); Long length=0L; try {
MultimediaInfo m = encoder.getInfo(source);
// 获取时长毫秒值 length = m.getDuration();
// 分钟 long minute = length / 60000;
// 秒钟 long second = (length - minute * 60000) / 1000; if (second < 10){ resultMap.put("timeLong",minute+":0"+second); }else { resultMap.put("timeLong", minute + ":" + second); } } catch (Exception e) { e.printStackTrace(); resultMap.put("status","N"); } return resultMap; }