思路: 前提是能被播放,无法被浏览器播放则无法获取时长,所以根据这一点,下面的方案也能判断视频能否被浏览器支持解码
<!DOCTYPE HTML><html>
<head>
<meta charset=utf-8>
<title>audio</title>
<script>
onload = function(){
ado.addEventListener("timeupdate",function(){
console.log(this.currentTime)
})
ado.addEventListener("loadedmetadata",function(){
this.play()
})
}
</script>
</head>
<body>
<audio id="ado" src="/i/horse.ogg" controls="controls">
Your browser does not support the audio element.
</audio>
</body>
</html>