Is there any way to run a predefined function when an HTML5 Audio element has played a certain amount (such as 50%, 80%)? Let's assume I know the size of the file and anything else.
<div class="audio-player" style="display:none;">
<audio id="music" preload="auto">
<source src="/path/to/my.mp3" type="audio/mp3">
</audio>
</div>
I'm already using Javascript to play/pause this audio.
function aud_play_pause(_id) {
var audio = document.getElementById("music");
if (audio.paused) {
audio.play();
} else {
audio.pause();
}
}
So let's say I had a function halfway() to tell if someone had listened to half the song, is there any way I can run this when the track reaches 50%? Even if this is an estimate, that's fine. I would also like to avoid the use of any frameworks, as I don't need any additional functionality.
Aucun commentaire:
Enregistrer un commentaire