1.源
在初学者的学习路上,遇到太多视频课程了,所以用自己有限的能力,写了个统计视频时长的程序,方便根据课时来安排选择课程。能力有限,并没有考虑效率优化。
2.功能
程序的核心是递归,传入文件夹的绝对地址,统计输出所有视频子文件的播放时长。
3.代码
import java.io.File;
import java.util.ArrayList;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.InputFormatException;
import it.sauronsoftware.jave.MultimediaInfo;
public class DurationStatictics4 {
public static void main(String[] args) throws InputFormatException, EncoderException {
MyFile my = new MyFile("dir", 0);
System.out.println(my.toString(true));
}
}
class MyFile {
// 文件名
String fileName;
String shortName;
// 持续时长,视频和文件夹为正数,其他为-1
long time;
// 文件层数
int level;
// 是否为文件夹
boolean isDir;
// 文件类型,视频为.mp4 .avi,其他为null
String type;
// 存储子文件,没有为null
ArrayList<MyFile> fileList;
// 根据文件名和层数创建文件
public MyFile(String fileName, int level) throws InputFormatException, EncoderException {
this.fileName = fileName;
this.level = level;
this.time = -1;
this