测试代码:
<body> Duration: <span id="d"></span> currentTime: <span id="c"></span> <script> var element_d = document.getElementById("d"); var element_c = document.getElementById("c"); var A = new Audio("test.mp3"); A.loop=true; A.ondurationchange=function(){ element_d.innerHTML = A.duration; } A.ontimeupdate=function(t){ element_c.innerHTML = A.currentTime; } A.play(); </script> </body>
Chromium M34上Audio API(HTMLMediaElement)播放音乐不能获取currentTime属性更新