package com.qxueyou.scc.sys.utils; 
 | 
  
 | 
import com.coremedia.iso.IsoFile; 
 | 
  
 | 
import java.io.IOException; 
 | 
  
 | 
  
 | 
public class VideoUtil { 
 | 
  
 | 
  
 | 
  
 | 
    /** 
 | 
     * »ñÈ¡ÊÓÆµÎļþµÄ²¥·Å³¤¶È(mp4¡¢mov¸ñʽ) 
 | 
     * @param videoPath 
 | 
     * @return µ¥Î»ÎªºÁÃë 
 | 
     */ 
 | 
    public static long getMp4Duration(String videoPath) throws IOException { 
 | 
        IsoFile isoFile = new IsoFile(videoPath); 
 | 
        long lengthInSeconds = 
 | 
                isoFile.getMovieBox().getMovieHeaderBox().getDuration() / 
 | 
                        isoFile.getMovieBox().getMovieHeaderBox().getTimescale(); 
 | 
        return lengthInSeconds; 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * µÃµ½ÓïÒô»òÊÓÆµÎļþʱ³¤,µ¥Î»Ãë 
 | 
     * @param filePath 
 | 
     * @return 
 | 
     * @throws IOException 
 | 
     */ 
 | 
    public static long getDuration(String filePath) throws IOException { 
 | 
        String format = getVideoFormat(filePath); 
 | 
        long result = 0; 
 | 
        if("wav".equals(format)){ 
 | 
            result = AudioUtil.getDuration(filePath).intValue(); 
 | 
        }else if("mp3".equals(format)){ 
 | 
            result = AudioUtil.getMp3Duration(filePath).intValue(); 
 | 
        }else if("m4a".equals(format)) { 
 | 
            result = VideoUtil.getMp4Duration(filePath); 
 | 
        }else if("mov".equals(format)){ 
 | 
            result = VideoUtil.getMp4Duration(filePath); 
 | 
        }else if("mp4".equals(format)){ 
 | 
            result = VideoUtil.getMp4Duration(filePath); 
 | 
        } 
 | 
  
 | 
        return result; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * µÃµ½ÓïÒô»òÊÓÆµÎļþʱ³¤,µ¥Î»Ãë 
 | 
     * @param filePath 
 | 
     * @return 
 | 
     * @throws IOException 
 | 
     */ 
 | 
    public static long getDuration(String filePath,String format) throws IOException { 
 | 
        long result = 0; 
 | 
        if("wav".equals(format)){ 
 | 
            result = AudioUtil.getDuration(filePath).intValue(); 
 | 
        }else if("mp3".equals(format)){ 
 | 
            result = AudioUtil.getMp3Duration(filePath).intValue(); 
 | 
        }else if("m4a".equals(format)) { 
 | 
            result = VideoUtil.getMp4Duration(filePath); 
 | 
        }else if("mov".equals(format)){ 
 | 
            result = VideoUtil.getMp4Duration(filePath); 
 | 
        }else if("mp4".equals(format)){ 
 | 
            result = VideoUtil.getMp4Duration(filePath); 
 | 
        } 
 | 
  
 | 
        return result; 
 | 
    } 
 | 
  
 | 
  
 | 
    /** 
 | 
     * µÃµ½Îļþ¸ñʽ 
 | 
     * @param path 
 | 
     * @return 
 | 
     */ 
 | 
    public static String getVideoFormat(String path){ 
 | 
        return  path.toLowerCase().substring(path.toLowerCase().lastIndexOf(".") + 1); 
 | 
    } 
 | 
  
 | 
  
 | 
} 
 |