开发者

HTML5 Audio onLoad

How can I get a callback when the audio tag is ready to play. (to tell the user, when implementing m开发者_运维百科y own controls)

Using Chrome.


Have only done this on the video element but it should work for audio.

Firstly, you can't bind the event, I don't know why that doesn't work. So you have to use setTimeout.

Example using jQuery:

$(function(){
    var audioReady = function(){
        if (youraudioelement.attr('readyState')) {
            alert("it's ready!");
        } else {
            setTimeout(audioReady, 250);
        }
    }
    audioReady();
}

More info: http://www.w3.org/TR/html5/video.html#the-ready-states


Can you not bind to the onloadeddata event? It works for me. W3C Reference


Have you looked at the canplaythrough event?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜