java 怎么获取音频文件时长?
File source =new File('d:\\test.mp3');
Encoder encoder = new Encoder();
MultimediaInfo m = encoder.getInfo(source);
long ls = m.getDuration();
duration = ls/1000;
System.out.println("此视频时长为:"+ls/60000+"分"+(ls/1000-ls/60000*60)+"秒!");
若用的是springmvc框架上传文件
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request;
Iterator<String> iter = multiRequest.getFileNames();
while(iter.hasNext()){
MultipartFile file = multiRequest.getFile(iter.next());
String fileOldName = file.getOriginalFilename();
long duration = 0;//音频长度,秒
CommonsMultipartFile cf= (CommonsMultipartFile)file;
DiskFileItem fi = (DiskFileItem)cf.getFileItem();
File source = fi.getStoreLocation();
Encoder encoder = new Encoder();
MultimediaInfo m = encoder.getInfo(source);
long ls = m.getDuration();
duration = ls/1000;}