用js监测html5的audio标签播放结束

发布时间:2018年10月28日 作者:未知 查看次数:1165

自:https://zhidao.baidu.com/question/1796332093475709507.html


用js监测html5的audio标签播放结束


HTML5中的audio对象有个属性为 ended,该属性是返回音频是否播放结束,是boolean类型的。


<!DOCTYPE HTML>

<html>

<body>


<audio id="audio" controls="true" autoplay="true">

<source src="/i/song.ogg" type="audio/ogg">

<source src="/i/song.mp3" type="audio/mpeg">

</audio>

<script>

var audio = document.getElementById("audio"); 

audio.loop = false;

audio.addEventListener('ended', function () {  

alert('over');

}, false);

</script> 

</body>

</html>




版权所有!www.sieye.cn
E.Mail:sieye@sohu.com QQ:66697110