获取视频信息的大小、时长等的工具类代码
public class FlieLen {public static String ReadVideoTime(File source) {Encoder encoder = new Encoder();String length = "";try {MultimediaInfo m = encoder.getInfo(source);long ls = m.getDuration() / 1000;int hour = (int) (ls / 3600);int minute = (int) (ls % 3600) / 60;int second = (int) (ls - hour * 3600 - minute * 60);if (hour == 0 || hour < 10) {length += "0" + hour + ":";} else {length += hour + ":";}if (minute == 0 || minute < 10) {length += "0" + minute + ":";} else {length += minute + ":";}if (second == 0 || second < 10) {length += "0" + second;} else {length += second;}} catch (Exception e) {e.printStackTrace();}return length;}/*** 获取视频大小** @param source* @return*/public static String ReadVideoSize(File source) {FileChannel fc = null;String size = "";try {@SuppressWarnings("resource")FileInputStream fis = new FileInputStream(source);fc = fis.getChannel();BigDecimal fileSize = new BigDecimal(fc.size());size = fileSize.divide(new BigDecimal(1048576), 2, RoundingMode.HALF_UP) + "MB";} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {if (null != fc) {try {fc.close();} catch (IOException e) {e.printStackTrace();}}}return size;}public static void main(String[] args) {File file = new File("E://123456.mp4");ReadVideoTime(file);ReadVideoSize(file);}
所需依赖
<dependency><groupId>jack.jave</groupId><artifactId>jave</artifactId><version>1.0.2</version><scope>system</scope><systemPath>${basedir}/src/main/resources/lib/jave-1.0.2.jar</systemPath></dependency>
