I am wanting to know how to check if a HTML5 audio element is loaded.
question from:https://stackoverflow.com/questions/8059434/how-do-you-check-if-a-html5-audio-element-is-loadedI am wanting to know how to check if a HTML5 audio element is loaded.
question from:https://stackoverflow.com/questions/8059434/how-do-you-check-if-a-html5-audio-element-is-loadedTo find out when the audio is ready to start playing, add listeners for the oncanplay
or oncanplaythrough
events. To find out when the audio has loaded at all, listen to the onloadeddata
event:
<audio oncanplay="myOnCanPlayFunction()"
oncanplaythrough="myOnCanPlayThroughFunction()"
onloadeddata="myOnLoadedData()"
src="myaudio.ogg"
controls>
<a href="myaudio.ogg">Download</a>
</audio>
<script>
function myOnCanPlayFunction() { console.log('Can play'); }
function myOnCanPlayThroughFunction() { console.log('Can play through'); }
function myOnLoadedData() { console.log('Loaded data'); }
</script>