开发者

Is there an event callback to know when html5 <audio> has loaded the audio and is playable?

开发者 https://www.devze.com 2023-03-26 17:20 出处:网络
I havecontrols 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.

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?


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


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) {};
0

精彩评论

暂无评论...
验证码 换一张
取 消