I want to show an alert after ten seconds playing audio.
<audio id="player01" controls src="01.mp3" ontimeupdate="test()"></audio>
js
var player01 = document.getElementById("player01");
function test(){
if (player01.currentTime == 10) {
alert (10);
}
};
Alert doesn't appear. Console is empty.
You would have to use the ontimeupdate
event:
var player01 = document.getElementById("player01");
player01.ontimeupdate = function() {
if (parseInt(this.currentTime) == 10) {
alert (10);
}
};
Reference:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.