获取视频播放长度

1、导入依赖 (jave-1.0.2.jar)

<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; }

 

posted on 2021-04-20 19:10  java老三  阅读(267)  评论(0)    收藏  举报

导航