直接上代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
</head>
<body>
<input type="file" accept="video/*" οnchange="setVideoSrc(this)" />
</body>
<script>
function setVideoSrc(el){
//获取视频对象
var content = el.files[0]
console.log(content)
//获取音频、视频时长
var url = URL.createObjectURL(content);
var audioElement = new Audio(url);
var duration;
audioElement.addEventListener("loadedmetadata", function (_event) {
duration = audioElement.duration;
console.log(duration+'s');
});
}
</script>
</html>