11

I have controls that load mp3 files from other sites, but if it take the audio file a while to start loading, the controls stay disabled for a few seconds and appear not to be working.

If I show an activity indicator when the audio control starts loading the resource, is there a callback I can use to hide the indicator when the audio control is ready to start playing the audio and ready for user interaction?

dan
  • 43,914
  • 47
  • 153
  • 254

2 Answers2

10

element.addEventListener('loadedmetadata', callback, false);

apart form loadedmetadata, load can also be used to see if the song is also loaded

https://developer.mozilla.org/en/Introducing_the_Audio_API_Extension

Achshar
  • 5,153
  • 8
  • 40
  • 70
2

You can use events on MediaControllers:

http://dev.w3.org/html5/spec/Overview.html#handler-mediacontroller-oncanplay

Example:

var controller = new MediaController();
var audio = document.createElement('audio');
audio.controller = controller;
audio.oncanplay = function (event) {};
Skomski
  • 4,827
  • 21
  • 30