贫民窟里的程序高手

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

本文转载自:http://blog.csdn.net/ntotl/article/details/50419983

下载 jave-1.0.2.jar

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;
}

 

posted on 2017-03-27 15:41  贫民窟里的程序高手  阅读(359)  评论(0编辑  收藏  举报