JS获取上传视频时长 您所在的位置:网站首页 layui学习视频 JS获取上传视频时长

JS获取上传视频时长

2023-01-05 04:58| 来源: 网络整理| 查看: 265

注:在不是layui框架的情况下也可以参考,因为不管什么框架最原始的东西都是对js代码的封装 1:首先写个div,里面包含video,用来放上传的视频

2:上传之后获取到视频地址,赋值在video标签上,然后通过自定义方法formatSeconds获取到视频时长

3:自定义事件formatSeconds function formatSeconds(value) { var theTime = parseInt(value);// 秒 var theTime1 = 0;// 分 var theTime2 = 0;// 小时 if (theTime > 60) { theTime1 = parseInt(theTime / 60); theTime = parseInt(theTime % 60); if (theTime1 > 60) { theTime2 = parseInt(theTime1 / 60); theTime1 = parseInt(theTime1 % 60); } }

var result = "" + parseInt(theTime);//秒 if (10 > theTime > 0) { result = "0" + parseInt(theTime);//秒 } else { result = "" + parseInt(theTime);//秒 } if (10 > theTime1 > 0) { result = "0" + parseInt(theTime1) + ":" + result;//分,不足两位数,首位补充0, } else { result = "" + parseInt(theTime1) + ":" + result;//分 } if (theTime2 > 0) { result = "" + parseInt(theTime2) + ":" + result;//时 } // console.log(result); return result; }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有