In this blog post I will share a snippet for you. It is an HTML5 code with some JavaScript functions in it.
You can play an mp3 audio file while you see a feedback about what seconds is the audio being played. You can modify the code, for example, to show an alert if the audio play time is 10 seconds; and so on.
Here is the script:
Audio Player
Current Time: 0 seconds
<script>
const audioPlayer = document.getElementById('audioPlayer');
const currentTimeDisplay = document.getElementById('currentTime');
audioPlayer.addEventListener('timeupdate', function() {
const currentTime = Math.floor(audioPlayer.currentTime);
currentTimeDisplay.textContent = `Current Time: ${currentTime} seconds`;
if(currentTime == 10){
alert("It is 10 seconds!");
}
});
</script>