h5配合javascript 通过video标签获取视频时长
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="file" id='upload'>
<button onclick='getVideoTime()'>获取时长</button>
</body>
<script>
function getVideoTime() {
var fileVIdeo = document.getElementById("upload").files[0]
var url = URL.createObjectURL(fileVIdeo);
var audioElement = new Audio(url);
audioElement.addEventListener("loadedmetadata", function (_event) {
var duration = audioElement.duration;
console.log("视频时长:"+duration+"秒");
});
}
</script>
</html>