import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.MultimediaInfo;
import java.io.File;
/**
* Created by yawn on 2017-07-04.
*/
public class VideoUtil {
/**
* 获取视频文件的播放长度
* @param source
* @return 单位为毫秒
* @throws EncoderException
*/
public long getDuration(File source) throws EncoderException {
Encoder encoder = new Encoder();
MultimediaInfo m = encoder.getInfo(source);
return m.getDuration();
}
public long getDuration(String videoPath) throws EncoderException {
File source = new File(videoPath);
return getDuration(source);
}
}
需要jar包 jave-1.0.2.jar,可在这里下载:
http://www.sauronsoftware.it/projects/jave/index.php
maven项目中,可先将jar安装在本地仓库,使用以下命令:
mvn install:install-file
-Dfile=jave-1.0.2.jar
-DgroupId=it.sauronsoftware
-DartifactId=jave
-Dversion=1.0.2
-Dpackaging=jar
再添加依赖如下即可使用:
<dependency>
<groupId>it.sauronsoftware</groupId>
<artifactId>jave</artifactId>
<version>1.0.2</version>
</dependency>