音频:
public static long getMp3Length(String url) { File file = new File(url); try { MP3File f = (MP3File) AudioFileIO.read(file); MP3AudioHeader audioHeader = (MP3AudioHeader) f.getAudioHeader(); // System.out.println(audioHeader.getTrackLength()); return audioHeader.getTrackLength(); } catch (Exception e) { e.printStackTrace(); } return 0; }
所需jar:jaudiotagger-1.0.jar
视频:
public static long getMp4Length(String url){ File file = new File(url); Encoder encoder = new Encoder(); try { MultimediaInfo multimediaInfo = encoder.getInfo(file); long ls = multimediaInfo.getDuration(); return ls/1000; } catch (Exception e) { e.printStackTrace(); } return 0; }
所需jar:jave-1.0.2.jar