zoukankan      html  css  js  c++  java
  • 前端JS获取视频时长的写法

    下面的代码直接可以使用,获取视频的时长,然后可以根据业务再具体写逻辑

    <!DOCTYPE html>
    <html>
    <head>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>js获取视频时长</title>
    </head>
    
    <body>
        <div>
            <video src="https://vdept.bdstatic.com/4d7353594449333461724852716d4747/424253456e584b79/59d96f0aa420b86938e7ebaeb47553c871ed1a661934348af5651aa12986c93eab77ed9603a021062dd6be2c523d7ea4.mp4?auth_key=1583929206-0-0-0d2202f24b6757a116072d28b1c7ecae"
                   controls preload="auto" id="player"></video>
        </div>
        <input name="submit" type="submit" onclick="getInfo();">
        <div>
            <script language="javascript">
                var time;
                function getInfo(){
                    var pl=document.getElementById("player");
                    time = pl.duration;
                    var totalSecond = Math.floor(time);
                    // 得到分钟数加秒数
                    if (totalSecond > 60){
                        var minute = Math.floor(totalSecond / 60) ;
                        if (minute < 10) {
                            minute = "0" + minute;
                        }
                        console.info("second --> " + totalSecond % 60);
                        console.info("minute + second --> " + minute + ":" + totalSecond % 60);
                    }
                    alert(totalSecond);
                }
            </script>
        </div>
    </body>
    </html>

  • 相关阅读:
    Windows异常处理机制介绍
    OD 与 Win7
    对VC6编译优化的简单测试
    QQ版本号(2012/07/22 更新)
    OD与调试符号
    Balsamiq Mockups
    hotpatch热修补
    QQ
    VC的编译开关参数大全
    隐藏秘技:vc输出类的layout信息
  • 原文地址:https://www.cnblogs.com/no8g/p/13415528.html
Copyright © 2011-2022 走看看