Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Audio Load Event?

Is there a load event that fires when an audio has finished loading? I am creating an audio element like so.

var myAudio = new Audio("mySound.mp3");
myAudio.load();

Tried adding an eventListener like so but it does not seem to fire.

myAudio.addEventListener("load",soundLoaded,false);
like image 352
user781657 Avatar asked Feb 18 '12 00:02

user781657


1 Answers

It sounds like you want the "canplaythrough" event. This fires when the browser thinks it can play the whole audio file without stopping.

Try:

myAudio.addEventListener('canplaythrough', soundLoaded, false);

There are 7 events that fire in this order when an audio file is loaded:

  1. loadstart
  2. durationchange
  3. loadedmetadata
  4. loadeddata
  5. progress
  6. canplay
  7. canplaythrough

Please note this is not supported in Internet Explorer versions before 9.

like image 104
jaybee Avatar answered Oct 10 '22 12:10

jaybee