js 获取视频的总时长

js 获取视频的总时长:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

<video id="videoPlayerNew" src="http://vfx.mtime.cn/Video/2019/03/18/mp4/190318231014076505.mp4" controls="controls">
your browser does not support the video tag
</video>
</body>
<script type="text/javascript">
    var vid = document.getElementById("videoPlayerNew");
        vid.onloadedmetadata = function() {
              console.log('metadata loaded!');
              console.log(vid.duration); //打印时长
        };
</script>
</html>

转自:https://stackoverflow.com/questions/40763057/trying-to-get-full-video-duration-but-returning-as-nan

原文地址:https://www.cnblogs.com/Ananiah/p/12879289.html