/**
* 获取视频时长
* @param filepath 视频地址
* @return
* @throws IOException
*/
public static String readVideoTime(String filepath) {
File localPath = new File("E:"+File.separator+"video"+UUID.randomUUID().toString());
if (!localPath.exists()) {localPath.mkdirs();}
File source = new File(filepath);
String length ="";
try{
MultimediaObject instance =new MultimediaObject(source);
MultimediaInfo result = instance.getInfo();
long ls = result.getDuration() /1000;
Integer hour = (int) (ls /3600);
Integer minute = (int) (ls %3600) /60;
Integer second = (int) (ls - hour *3600- minute *60);
String hr = hour.toString();
String mi = minute.toString();
String se = second.toString();
if(hr.length() <2) {hr ="0"+ hr;}
if(mi.length() <2) {mi ="0"+ mi;}
if(se.length() <2) {se ="0"+ se;}
length = hr +":"+ mi +":"+ se;}
catch(Exception e)
{e.printStackTrace();
java读取本地视频文件的时长
最新推荐文章于 2025-05-10 14:15:00 发布