File source = new File("视频.mp4"); Encoder encoder = new Encoder(); try { MultimediaInfo info = encoder.getInfo(source); System.out.println("dura="+info.getDuration()); Date date = new Date(info.getDuration()); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss",Locale.getDefault()); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); System.out.println("时长="+sdf.format(date)); } catch (Exception e) { }
引入jar包下载地址
http://www.sauronsoftware.it/projects/jave/download.php
使用新版jave
File file = new File("视频或者音频"); MultimediaObject object = new MultimediaObject(file); //这里就是计算的时长 long duration = object.getInfo().getDuration();
引入包
<dependency> <groupId>ws.schild</groupId> <artifactId>jave-core</artifactId> <version>2.4.6</version> </dependency> <dependency> <groupId>ws.schild</groupId> <artifactId>jave-native-win64</artifactId> <version>2.4.6</version> </dependency>