简体   繁体   中英

show alert after audio playing specific time

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:

http://www.w3schools.com/tags/av_event_timeupdate.asp

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM