yydl
yydl

Reputation: 24464

HTML5 Audio onLoad

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.

Upvotes: 5

Views: 6626

Answers (3)

Lee Goddard
Lee Goddard

Reputation: 11173

Have you looked at the canplaythrough event?

Upvotes: 0

rewolf
rewolf

Reputation: 5871

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

Upvotes: 4

bcoughlan
bcoughlan

Reputation: 26617

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

Upvotes: 7

Related Questions