Java 视频时长计算

计算某个文件夹下面所有wmv视频的总时长:

  String path = "F:\\BaiduNetdiskDownload\\Python\\尚硅谷Python项目之谷粒教育\\视频";
        File file = new File(path);
        File[] tempList = file.listFiles();
        if (tempList != null) {
            long ls1 = 0;
            for (int i = 0; i < tempList.length; i++) {

//                if (tempList[i].isDirectory()) {
                    if (tempList[i].getAbsolutePath().endsWith(".wmv")) {
                        Encoder encoder = new Encoder();
                        try {
                            MultimediaInfo m = encoder.getInfo(tempList[i]);
                            long ls = m.getDuration();
                            ls1 += ls;
                        } catch(Exception e) {
                            e.printStackTrace();
                        }
                    }
//                }
            }
            System.out.println("学习时长:"+(ls1/3600/1000)+"小时");
        }

其他视频请改 

if (tempList[i].getAbsolutePath().endsWith(".wmv")) {

这一句代码的后缀,下载jar包地址http://www.sauronsoftware.it/projects/jave/download.php

你可能感兴趣的:(Java,Java,视频)