HTML5 Audio onLoad

后端 未结 3 1531
天涯浪人
天涯浪人 2021-01-05 22:19

How can I get a callback when the audio tag is ready to play. (to tell the user, when implementing my own controls)

Using Chrome.

3条回答
  •  一整个雨季
    2021-01-05 22:34

    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

提交回复
热议问题