Feng Huo Feng Huo - 1 month ago 5
Javascript Question

Tell whether video is loaded or not in Javascript

So, I've been using a listener on

document.getElementById("video").buffered.length


to see if it's greater than
0
for when a video's loaded or not. This works for a very small video, and only in Google Chrome. It doesn't work in Firefox at all. Any ideas for how to get this to work?

I essentially want to wait till 3 seperate videos are loaded to take a specific action, how do I go about this?

Answer

Try this:

var video = document.getElementById("video-id-name");

if ( video.readyState === 4 ) {
    // it's loaded
}

Read here: https://developer.mozilla.org/en/DOM/HTMLMediaElement

Comments